且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在NativeScript中以编程方式打开本机设置菜单页面

更新时间:2023-10-03 09:45:40

这可以使用模块tns-core-modules/application来实现,该模块将使startActivity可用.下面提供了一个使用TypeScript的示例:

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);

不幸的是,foregroundActivitystartActivity不包含TypeScript类型,这使得寻找解决方案变得非常困难. 非常感谢 user10655801 包含解决方案的测试仓库.

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.