1

I am using android 6.0 to build my app in android studio. When running the app, it seems all permissions for that app is not enabled automatically. Need to give the permission manually from settings->apps->app_name then enables specific permission.

Is there any way to enable all the permission during running the app using android studio?

0xAliHn
  • 18,390
  • 23
  • 91
  • 111
  • 1
    That's one of the main feature of android 6.0 getting runtime permission from users. So u can't give permission by yourself through code. – HourGlass Aug 25 '16 at 03:49
  • Starting in 6.0, it's highly recommended to only ask the user for "dangerous" permissions the moment your app needs them. So if your app had a "get my location" button, you should only prompt the user for the location permission once they touch the button. You could spam the user with permission dialogs on app start but that's a pretty terrible experience and might scare away users. Give [this](https://developer.android.com/training/permissions/requesting.html) a read for some info about it – Aystub Aug 25 '16 at 03:52
  • See http://stackoverflow.com/a/36937109/1770868 – Ahmad Aghazadeh Dec 03 '16 at 13:02
  • And see http://stackoverflow.com/a/37546500/1770868 – Ahmad Aghazadeh Dec 03 '16 at 13:03

2 Answers2

0

On Android 6, you definitely must ask user accept permission. This is a good example about it https://stackoverflow.com/a/34722591/4051322

Community
  • 1
  • 1
Lê Vũ Huy
  • 714
  • 6
  • 16
0

I think you can try this

 private void Verifypermissions()
{
    Log.d(TAG,"Verify permissions: asking user for permissions");
    String[] permissions={Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.CAMERA};
    if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
            permissions[0])== PackageManager.PERMISSION_GRANTED
            && ContextCompat.checkSelfPermission(this.getApplicationContext(),
            permissions[1])==PackageManager.PERMISSION_GRANTED
            && ContextCompat.checkSelfPermission(this.getApplicationContext(),
            permissions[2])==PackageManager.PERMISSION_GRANTED)
    {
        return;
    }

    else
    {
        ActivityCompat.requestPermissions(MainActivity.this,permissions,REQUEST_CODE);
    }

}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    Verifypermissions();
}

you can include the required permissions inside the string array

Dhyan V
  • 621
  • 1
  • 8
  • 18