(轉)安卓6.0系統權限申請android.permission.WRITE_SETTINGS (亮度調節)

原地址:http://blog.csdn.net/hnkwei1213/article/details/54947339java

 

 

app用到了調整系統亮度的功能,在清單文件中添加了android.permission.WRITE_SETTINGS權限,但運行在6.0系統一直報錯:java.lang.SecurityException: so.wih.android.jjewatch was not granted this permission: android.permission.WRITE_SETTINGS.android

解決方法以下:app

 
  1.  
    //設置系統亮度
  2.  
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  3.  
    if (!Settings.System.canWrite(context)) {
  4.  
    Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
  5.  
    intent.setData(Uri.parse("package:" + context.getPackageName()));
  6.  
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  7.  
    context.startActivity(intent);
  8.  
    } else {
  9.  
    //有了權限,具體的動做
  10.  
    Settings.System.putInt(getContentResolver(),
  11.  
    Settings.System.SCREEN_BRIGHTNESS, progress);
  12.  
    data2 = intToString(progress, 255);
  13.  
    tvSunlightValue.setText(data2 + "%");
  14.  
    }
  15.  
    }
相關文章
相關標籤/搜索