在NativeScript中以编程方式打开本机设置菜单页面 [英] Opening a native settings menu page programmatically in NativeScript

查看:89
本文介绍了在NativeScript中以编程方式打开本机设置菜单页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用NativeScript从Android本机设置菜单中以编程方式打开页面? 经典的Java示例显示可以通过以下方式完成此操作:

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

但是如何在NativeScript中做同样的事情?

but how to do the same in NativeScript?

推荐答案

这可以使用模块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.

这篇关于在NativeScript中以编程方式打开本机设置菜单页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆