I got problem with brightness. On most devices it works, but i got problem with Nexus 5 and SGS4. Brightness just don't changing. Here is the my function:
@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 now not detecting any problems and app keeps workig. What do i do wrong?