下面列出了android.provider.Settings.SettingNotFoundException#printStackTrace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static boolean isLocationEnabled(Context context) {
if (VERSION.SDK_INT >= 19) {
try {
if (Secure.getInt(context.getContentResolver(), "location_mode") != 0) {
return true;
}
return false;
} catch (SettingNotFoundException e) {
e.printStackTrace();
return false;
}
} else if (TextUtils.isEmpty(Secure.getString(context.getContentResolver(), "location_providers_allowed"))) {
return false;
} else {
return true;
}
}
/**
* Is Roaming enabled.
*
* @return
*/
@SuppressWarnings("deprecation")
private static boolean isRoamingEnabled(Context ctx) {
ContentResolver cr = ctx.getContentResolver();
int result = 0; // 0 is false
boolean check = false;
try {
result = Settings.Secure.getInt(cr, Settings.Secure.DATA_ROAMING);
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
if (result == 1) {
check = true;
}
return check;
}
@TargetApi(android.os.Build.VERSION_CODES.FROYO)
private void initBrightnessTouch() {
float brightnesstemp = 0.6f;
// Initialize the layoutParams screen brightness
try {
if (AndroidUtil.isFroyoOrLater() &&
Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
Settings.System.putInt(getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
mRestoreAutoBrightness = android.provider.Settings.System.getInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f;
} else {
brightnesstemp = android.provider.Settings.System.getInt(getContentResolver(),
android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f;
}
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightnesstemp;
getWindow().setAttributes(lp);
mIsFirstBrightnessGesture = false;
}
private static boolean isAccessibilityServiceRunning(Context context) {
boolean serviceRunning = false;
try {
ContentResolver contentResolver = context.getContentResolver();
int a11yEnabled = Settings.Secure.getInt(contentResolver,
Settings.Secure.ACCESSIBILITY_ENABLED);
if (a11yEnabled == 1) {
serviceRunning = true;
}
} catch (SettingNotFoundException e) {
Log.w(TAG, "Unexpected SettingNotFoundException");
e.printStackTrace();
}
return serviceRunning;
}
private static boolean isAccessibilitySettingsOn(Context ctx) {
int accessibilityEnabled = 0;
final String service = ctx.getPackageName() + "/"
+ OversecAccessibilityService_1.class.getName();
boolean accessibilityFound = false;
try {
accessibilityEnabled = Settings.Secure.getInt(ctx
.getApplicationContext().getContentResolver(),
Settings.Secure.ACCESSIBILITY_ENABLED);
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
if (accessibilityEnabled == 1) {
String settingValue = Settings.Secure.getString(ctx
.getApplicationContext().getContentResolver(),
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
if (settingValue != null) {
String[] values = settingValue.split("\\:");
for (String string : values) {
if (string.equalsIgnoreCase(service)) {
return true;
}
}
}
}
return accessibilityFound;
}
/**
* 获取当前屏幕亮度,范围0-255
*
* @param context
* @return 屏幕当前亮度值
*/
public static int getScreenBrightness(Context context) {
int rightnessValue = 0;
try {
rightnessValue = Settings.System.getInt(
context.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS);
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
return rightnessValue;
}
/**
* 判断是否开启了自动亮度调节
*
* @param context
* @return
*/
public static boolean isAutomicBrightness(Context context) {
boolean automicBrightness = false;
try {
automicBrightness = Settings.System.getInt(
context.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
return automicBrightness;
}
/**
* judge if auto open brightness
*
* @param context
* @return
*/
public boolean isAutoBrightness(Context context) {
boolean automicBrightness = false;
ContentResolver ctr = context.getContentResolver();
try {
automicBrightness = Settings.System.getInt(ctr,
Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return automicBrightness;
}
public static boolean isAutoBrightness(ContentResolver aContentResolver) {
boolean automicBrightness = false;
try {
automicBrightness = Settings.System.getInt(aContentResolver,
Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
return automicBrightness;
}