[英]android: how to set the “user-permission” within the “MainActivity.java” file
I am developing an android app that is implementing the Wifi P2P framework ...the user-permissions are set on the Manifest.xml
as follow: 我正在开发一个实现Wifi P2P框架的Android应用程序...用户权限在
Manifest.xml
上设置如下:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
.. and, I believe, the P2P service is enabled once I start my app (and on resume) ... and I do not want that anymore ...ie: enabling the P2P service automatically .. ..而且,我相信,一旦我启动我的应用程序(以及恢复),P2P服务就会启用...我不再需要了...即:自动启用P2P服务..
I want to be able to set a ToggleButton
that enables or disables these permissions from within my MainActivity.java
file. 我希望能够设置一个
ToggleButton
,从我的MainActivity.java
文件中启用或禁用这些权限。 here is my ToggleButton
code: 这是我的
ToggleButton
代码:
public void onToggleClicked(View view) {
Button btnDiscover = (Button) findViewById(R.id.btnDiscover);
boolean on = ((ToggleButton) view).isChecked();
if (on) {
// Enable the P2P service
} else {
}
}
How can I do this ? 我怎样才能做到这一点 ?
PS: I am new to android and Java programming PS:我是android和Java编程的新手
No. The user needs to be informed about the permissions while installing the application. 不需要。在安装应用程序时,需要通知用户有关权限的信息。 Askling them at runtime would be a security risk.
在运行时询问它们会带来安全风险。 And google doesn't like possible security-leaks.
谷歌不喜欢可能的安全漏洞。
Instead of changing the permissions dynamically...Use a boolean variable . 而不是动态更改权限...使用布尔变量 。 If it true proceed other wise don't proceed further...the variable default value is false
如果确实如此,则继续进行其他操作......变量默认值为false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.