简体   繁体   中英

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:

<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 ..

I want to be able to set a ToggleButton that enables or disables these permissions from within my MainActivity.java file. here is my ToggleButton code:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM