Opening a native settings menu page programmatically in NativeScript

空扰寡人 提交于 2019-12-13 03:54:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!