我正在使用android 6.0在android studio中构建我的应用程序。运行应用程序时,似乎未自动启用该应用程序的所有权限。需要从settings->apps->app_name
手动授予权限,然后才能启用特定权限。
有没有办法在使用android studio运行应用程序时启用所有权限?
在Android 6上,你一定要问用户接受权限。这是关于它的一个很好的例子https://stackoverflow.com/a/34722591/4051322
我想你可以尝试一下
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();
}
您可以在字符串数组中包含所需的权限