我正在我正在使用的Android应用程序中请求运行时权限。但是,一旦我运行了该应用程序,即使我接受了运行时权限,设备上仍会继续请求运行时权限。
我正在使用的代码如下:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
int PERMISSION_ALL = 1;
String[] PERMISSIONS = {
Manifest.permission.SET_TIME,
Manifest.permission.ACCOUNT_MANAGER,
Manifest.permission.RECEIVE_BOOT_COMPLETED,
Manifest.permission.CAMERA,
Manifest.permission.READ_SMS,
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.CHANGE_WIFI_STATE,
Manifest.permission.CHANGE_NETWORK_STATE,
Manifest.permission.INSTALL_PACKAGES,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.KILL_BACKGROUND_PROCESSES,
Manifest.permission.REBOOT,
Manifest.permission.WRITE_SETTINGS,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.WAKE_LOCK,
Manifest.permission.GET_ACCOUNTS,};
for (String permission : PERMISSIONS)
{
// count ++;
if (!hasPermissions(this, permission))
{
ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
}
}
} else
{
android.provider.Settings.System.putInt(getContentResolver(),
Settings.System.SCREEN_OFF_TIMEOUT, Integer.MAX_VALUE);
}
我还包括了hasPermissions方法:
public boolean hasPermissions(Context context, String permissions)
{
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && context != null && permissions != null)
{
if (ActivityCompat.checkSelfPermission(context, permissions) != PackageManager.PERMISSION_GRANTED)
{
return false;
}
}
return true;
}