I am working on giving the runtime permissions to my android device . In my case as soon as user clicks on Call button it should ask for 3 permissions CALL_PHONE,CAMERA and RECORD_AUDIO. It is asking for permissions I can see in the log but only one of the permission is being granted. Again if I kill my app and click on Call button now second permission is being asked and nxt time the lats one. All 3 are not being asked at the same time. As I can see in the log it asks and grants all the permission in the first time only but only one is asked in one time.
@JavascriptInterface
public void askPermission(String permission){
Log.d("Ask permission", permission);
switch (permission){
case "audioCall":
askForPermission(Manifest.permission.CALL_PHONE,CALL_PHONE);
askForPermission(Manifest.permission.CAMERA,CAMERA);
askForPermission(Manifest.permission.RECORD_AUDIO,RECORD_AUDIO);
break;
case "videoCall":
askForPermission(Manifest.permission.CALL_PHONE,CALL_PHONE);
askForPermission(Manifest.permission.CAMERA,CAMERA);
askForPermission(Manifest.permission.RECORD_AUDIO,RECORD_AUDIO);
break;
case "writeExternalStorage":
askForPermission(Manifest.permission.CALL_PHONE,CALL_PHONE);
askForPermission(Manifest.permission.CAMERA,CAMERA);
askForPermission(Manifest.permission.RECORD_AUDIO,RECORD_AUDIO);
break;
case "WRITE_EXTERNAL_STORAGE":
askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,WRITE_EXTERNAL_STORAGE);
break;
case "GET_ACCOUNTS":
askForPermission(Manifest.permission.GET_ACCOUNTS,GET_ACCOUNTS);
break;
case "READ_CONTACTS":
askForPermission(Manifest.permission.READ_CONTACTS,READ_CONTACTS);
break;
}
}
public void askForPermission(String permission, Integer requestCode){
Log.d("Permissions requested is+", permission);
if (ContextCompat.checkSelfPermission(MainActivity.this, permission) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, permission)) {
Log.d("Permission is already granted", ""+permission);
//This is called if user has denied the permission before
//In this case I am just asking the permission again
ActivityCompat.requestPermissions(MainActivity.this, new String[]{permission}, requestCode);
} else {
Log.d("asking for permissions", ""+permission);
ActivityCompat.requestPermissions(MainActivity.this, new String[]{permission}, requestCode);
}
} else {
/* Toast.makeText(this, "" + permission + " is already granted.", Toast.LENGTH_SHORT).show();*/
Log.d("Permission is already granted", ""+permission);
}
}
logs.txt
12-01 15:36:54.911: D/Ask permission(20783): videoCall
12-01 15:36:54.912: D/Permissions requested is+(20783): android.permission.CALL_PHONE
12-01 15:36:54.912: D/Permission is already granted(20783): android.permission.CALL_PHONE
12-01 15:36:54.912: D/Permissions requested is+(20783): android.permission.CAMERA
12-01 15:36:54.913: D/Permission is already granted(20783): android.permission.CAMERA
12-01 15:36:54.921: D/Permissions requested is+(20783): android.permission.RECORD_AUDIO
12-01 15:36:54.923: D/Permission is already granted(20783): android.permission.RECORD_AUDIO