问题
How can you programmatically open a page from the native Android settings menu using NativeScript? Classic java examples show it can be done this way:
Intent intent = new Intent(Settings.ACTION_SETTINGS);
startActivity(intent);
but how to do the same in NativeScript?
回答1:
This can be achieved using the module tns-core-modules/application
, which will make startActivity
available. An example using TypeScript is provided below:
import * as appM from 'tns-core-modules/application';
const intent = new android.content.Intent(android.provider.Settings.ACTION_SETTINGS);
const activity = appM.android.foregroundActivity || appM.android.startActivity;
activity.startActivityForResult(intent, 0);
Unfortunately, TypeScript types are not included for foregroundActivity
and startActivity
, which made finding a solution to this extremely hard.
A big thanks to user10655801 for his test repo containing the solution.
来源:https://stackoverflow.com/questions/58892418/opening-a-native-settings-menu-page-programmatically-in-nativescript