android - permissions are gone when app is removed from background -


i asking permissions on android app on runtime on marshmallow , above devices. permissions granted killed app (remove background not force stop)the permissions gone , asks permissions again when again open app.

boolean granted=checkpermission();     log.d("permission there","---"+granted );// returns false      if (build.version.sdk_int >= 23) {         system.out.println("build version is"+build.version.sdk_int);         if(!granted){             requestpermission();         }     }     private void requestpermission() {      activitycompat.requestpermissions(activity,new string[]{             manifest.permission.access_fine_location,             manifest.permission.record_audio,             manifest.permission.call_phone,             manifest.permission.camera,             manifest.permission.write_external_storage,             manifest.permission.read_contacts,             manifest.permission.get_accounts,      },requestpermissioncode);  } @override public void onrequestpermissionsresult(int requestcode, string permissions[], int[] grantresults) {     switch (requestcode) {      case requestpermissioncode:          if (grantresults.length > 0) {              boolean access_fine_location = grantresults[0] == packagemanager.permission_granted;             boolean record_audio = grantresults[1] == packagemanager.permission_granted;             boolean call_phone = grantresults[2] == packagemanager.permission_granted;             boolean camera = grantresults[3] == packagemanager.permission_granted;             boolean write_external_storage = grantresults[4] == packagemanager.permission_granted;             boolean get_accounts = grantresults[5] == packagemanager.permission_granted;             boolean read_contacts = grantresults[6] == packagemanager.permission_granted;                if (access_fine_location && record_audio && call_phone && camera && write_external_storage && get_accounts && read_contacts) {                  toast.maketext(mainactivity.this, "permission granted", toast.length_long).show();             }             else {                 toast.maketext(mainactivity.this,"permission denied",toast.length_long).show();              }         }          break;     } }  public boolean checkpermission() {       int firstpermissionresult= contextcompat.checkselfpermission(mainactivity.this, manifest.permission.access_fine_location);     int secondpermissionresult=contextcompat.checkselfpermission(mainactivity.this, manifest.permission.record_audio);     int thirdpermissionresult=contextcompat.checkselfpermission(mainactivity.this, manifest.permission.call_phone);     int fourthpermissionresult=contextcompat.checkselfpermission(mainactivity.this, manifest.permission.camera);     int fifthpermissionresult=contextcompat.checkselfpermission(mainactivity.this, manifest.permission.write_external_storage);     int sixthpermissionresult=contextcompat.checkselfpermission(mainactivity.this, manifest.permission.get_accounts);     int seventhpermissionresult=contextcompat.checkselfpermission(mainactivity.this, manifest.permission.read_contacts);      return firstpermissionresult == packagemanager.permission_granted &&             secondpermissionresult == packagemanager.permission_granted &&             thirdpermissionresult == packagemanager.permission_granted &&              fourthpermissionresult == packagemanager.permission_granted &&             fifthpermissionresult == packagemanager.permission_granted &&             sixthpermissionresult == packagemanager.permission_granted &&             seventhpermissionresult == packagemanager.permission_granted; } 

from android source , docs in packagemanager

public static final int permission_denied = -1; public static final int permission_granted = 0; 

and in code, adding permission results of permissions. if 1 item permission not granted, result variable becomes -1 , method returns false;

another issue code is, asking permissions stuffs vibrate please read doc know difference between normal , dangerous permissions.

last important issue, asking runtime permissions @ once not recommended google. , there chances app store reject app not following permissions guidelines

edit: remove these permissions list , try again

manifest.permission.modify_audio_settings manifest.permission.capture_audio_output manifest.permission.capture_video_output manifest.permission.capture_secure_video_output manifest.permission.access_network_state manifest.permission.vibrate 

please read doc, mentioned don't ask run time permissions normal permissions


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -