I am designing an app in android studio.i have included the all permission like CAMERA
and READCONTECTS
etc... in the AndroidManifest.xml file. It is working properly in all versions of android except Marshmallow. How do I set all permission by default?
Asked
Active
Viewed 243 times
-5

Phantômaxx
- 37,901
- 21
- 84
- 115

Ramesh Yogu
- 135
- 7
-
Google for runtime permission. This question should be closed. – rohitanand Dec 14 '17 at 10:23
-
Ramesh Yogu,what you have tried so far to show multiple permissions – Nithin Dec 14 '17 at 10:23
-
1Possible duplicate of [How to check Grants Permissions at Run-Time?](https://stackoverflow.com/questions/30549561/how-to-check-grants-permissions-at-run-time) – Dharmishtha Dec 14 '17 at 10:26
1 Answers
0
You need to set permission on the java code also before it works
Example:
//declaration
private static final Integer CAMERA = 0x1;
//call this
askForPermission(Manifest.permission.CAMERA, CAMERA);
/**
*
* @param permission
* @param requestCode
*/
private void askForPermission(String permission, Integer requestCode) {
if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
//This is called if user has denied the permission before
//In this case I am just asking the permission again
ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);
} else {
ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);
}
} else {
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if(ActivityCompat.checkSelfPermission(this, permissions[0]) ==
PackageManager.PERMISSION_GRANTED){
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
}
}else{
Toast.makeText(this, "Permission not granted", Toast.LENGTH_SHORT).show();
}
}

Leonce BALI
- 3
- 3