亮度问题。在大多数设备上都可以使用,但是我遇到了 Nexus 5和SGS4 的问题。亮度不会改变。这是我的功能:
@Nullable
private Integer setBrightness(int brightness) {
ContentResolver cResolver;
if (ContextCompat.checkSelfPermission(getContext(),
android.Manifest.permission.WRITE_SETTINGS)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(),
android.Manifest.permission.WRITE_SETTINGS)) {
} else {
ActivityCompat.requestPermissions(getActivity(),
new String[]{android.Manifest.permission.WRITE_SETTINGS}, 0);
}
return null;
} else {
cResolver = getContext().getContentResolver();
int prevBrg;
try
{
Settings.System.putInt(cResolver,
Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
prevBrg = Settings.System.getInt(cResolver, Settings.System.SCREEN_BRIGHTNESS);
}
catch (Settings.SettingNotFoundException e)
{
Log.e("Error", "Cannot access system brightness");
e.printStackTrace();
return null;
}
Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS, brightness);
return prevBrg;
}
}
Logcat现在没有检测到任何问题,应用程序保持workig。我做错了什么?