Java Code Examples for android.provider.Settings#SettingNotFoundException
The following examples show how to use
android.provider.Settings#SettingNotFoundException .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From Android-BLE with Apache License 2.0 | 6 votes |
public static boolean isGpsOpen(Context context) { int locationMode = 0; String locationProviders; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); } catch (Settings.SettingNotFoundException e) { e.printStackTrace(); return false; } return locationMode != Settings.Secure.LOCATION_MODE_OFF; } else { locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); return !TextUtils.isEmpty(locationProviders); } }
Example 2
Source File: LocationUtil.java From RxAndroidBootstrap with Apache License 2.0 | 6 votes |
public static boolean isLocationEnabled(Context context) { int locationMode = 0; String locationProviders; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ try { locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); } catch (Settings.SettingNotFoundException e) { e.printStackTrace(); } return locationMode != Settings.Secure.LOCATION_MODE_OFF; }else{ locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); return !TextUtils.isEmpty(locationProviders); } }
Example 3
Source File: USSDController.java From VoIpUSSD with Apache License 2.0 | 6 votes |
protected static boolean isAccessibilitySettingsOn(Context context, final String service) { int accessibilityEnabled = 0; try { accessibilityEnabled = Settings.Secure.getInt( context.getApplicationContext().getContentResolver(), android.provider.Settings.Secure.ACCESSIBILITY_ENABLED); } catch (Settings.SettingNotFoundException e) { // } if (accessibilityEnabled == 1) { String settingValue = Settings.Secure.getString( context.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); if (settingValue != null) { TextUtils.SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter(':'); splitter.setString(settingValue); while (splitter.hasNext()) { String accessabilityService = splitter.next(); if (accessabilityService.equalsIgnoreCase(service)) { return true; } } } } return false; }
Example 4
Source File: ScreenOrientationSwitcher.java From android-jungle-mediaplayer with Apache License 2.0 | 6 votes |
private boolean isScreenAutoRotate() { Context context = mContextRef.get(); if (context == null) { return false; } int gravity = 0; try { gravity = Settings.System.getInt(context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION); } catch (Settings.SettingNotFoundException e) { e.printStackTrace(); } return gravity == 1; }
Example 5
Source File: AppUtils.java From WaterMonitor with Apache License 2.0 | 6 votes |
public static boolean checkAccessibility(String service) { int ok = 0; try { ok = Settings.Secure.getInt(AppApplication.getContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED); } catch (Settings.SettingNotFoundException e) { } TextUtils.SimpleStringSplitter ms = new TextUtils.SimpleStringSplitter(':'); if (ok == 1) { String settingValue = Settings.Secure.getString(AppApplication.getContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); if (settingValue != null) { ms.setString(settingValue); while (ms.hasNext()) { String accessibilityService = ms.next(); if (accessibilityService.equalsIgnoreCase(service)) { return true; } } } } return false; }
Example 6
Source File: MediaPlayerFragment.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
private void initBrightnessTouch() { // if (!(getContext() instanceof Activity)) { // return; // } Activity activity = fragActivity;//(Activity) getContext(); WindowManager.LayoutParams lp = activity.getWindow().getAttributes(); float brightnesstemp = lp.screenBrightness != -1f ? lp.screenBrightness : 0.6f; // Initialize the layoutParams screen brightness try { if (Settings.System.getInt(activity.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) { if (!Permissions.canWriteSettings(activity)) { return; } Settings.System.putInt(activity.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); // restoreAutoBrightness = android.provider.Settings.System.getInt(activity.getContentResolver(), // android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f; } else if (brightnesstemp == 0.6f) { brightnesstemp = android.provider.Settings.System.getInt(activity.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS) / 255.0f; } } catch (Settings.SettingNotFoundException e) { e.printStackTrace(); } lp.screenBrightness = brightnesstemp; activity.getWindow().setAttributes(lp); mIsFirstBrightnessGesture = false; }
Example 7
Source File: BrightnessUtils.java From FriendBook with GNU General Public License v3.0 | 5 votes |
/** * 判断是否开启了自动亮度调节 * * @return */ public static boolean isAutoBrightness(Activity activity) { boolean autoBrightness = false; try { autoBrightness = Settings.System.getInt(activity.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC; } catch (Settings.SettingNotFoundException e) { e.printStackTrace(); } return autoBrightness; }
Example 8
Source File: WelcomeActivity.java From heads-up with GNU General Public License v3.0 | 5 votes |
public static boolean isAccessibilityEnabled(Context context){ int accessibilityEnabled = 0; try { accessibilityEnabled = Settings.Secure.getInt(context.getContentResolver(),android.provider.Settings.Secure.ACCESSIBILITY_ENABLED); Mlog.d(logTag, "ACCESSIBILITY: " + accessibilityEnabled); } catch (Settings.SettingNotFoundException e) { Mlog.d(logTag, "Error finding setting, default accessibility to not found: " + e.getMessage()); } TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':'); if (accessibilityEnabled==1){ String settingValue = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); Mlog.d(logTag, "Setting: " + settingValue); if (settingValue != null) { mStringColonSplitter.setString(settingValue); while (mStringColonSplitter.hasNext()) { String accessibilityService = mStringColonSplitter.next(); Mlog.d(logTag, "Setting: " + accessibilityService); if (accessibilityService.equalsIgnoreCase(ACCESSIBILITY_SERVICE_NAME)){ Mlog.d(logTag, "We've found the correct setting - accessibility is switched on!"); return true; } else if (Build.VERSION.SDK_INT < 18 && "com.pushbullet.android/com.pushbullet.android.notifications.mirroring.CompatNotificationMirroringService".equals(accessibilityService)) { // For easier translation in case of other troublesome services Toast.makeText(context, String.format(context.getString(R.string.accessibility_service_blocked), "PushBullet Notification Mirroring"), Toast.LENGTH_LONG).show(); } } } } else{ Mlog.d(logTag, "***ACCESSIBILITY IS DISABLED***"); } return false; }
Example 9
Source File: BaseTestCase.java From AndroidMvc with Apache License 2.0 | 5 votes |
@SuppressLint("NewApi") @SuppressWarnings("deprecation") protected boolean isDontKeepActivities() throws Settings.SettingNotFoundException { try { int val; if (Build.VERSION.SDK_INT > 16) { val = Settings.System.getInt(activity.getContentResolver(), Settings.Global.ALWAYS_FINISH_ACTIVITIES); } else { val = Settings.System.getInt(activity.getContentResolver(), Settings.System.ALWAYS_FINISH_ACTIVITIES); } return val != 0; } catch (Exception e) { return false; } }
Example 10
Source File: ChromeWebApkHost.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Returns whether the user has enabled installing apps from sources other than the Google Play * Store. */ private static boolean installingFromUnknownSourcesAllowed(Context context) { try { return Settings.Secure.getInt( context.getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS) == 1; } catch (Settings.SettingNotFoundException e) { return false; } }
Example 11
Source File: DetectionHelper.java From ml-authentication with Apache License 2.0 | 5 votes |
/** * Increase screen brightness by a certain rate * @param context * @param currentImageBrightness */ private static synchronized void setIncreasedScreenBrightness(Context context, double currentImageBrightness){ try { int currentScreenBrightness = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS); int increasedScreenBrightness = currentScreenBrightness + SCREEN_BRIGHTNESS_INCREASE_RATE; if (increasedScreenBrightness <= SCREEN_BRIGHTNESS_MAX){ Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, increasedScreenBrightness); Log.i(DetectionHelper.class.getName(), "setIncreasedScreenBrightness: Screen brightness has been increased: currentImageBrightness: " + currentImageBrightness + " currentScreenBrightness: " + currentScreenBrightness + " increasedScreenBrightness: " + increasedScreenBrightness); } } catch (Settings.SettingNotFoundException e) { Log.e(DetectionHelper.class.getName(), null, e); } }
Example 12
Source File: AccessibilityUtils.java From FreezeYou with Apache License 2.0 | 5 votes |
public static boolean isAccessibilitySettingsOn(Context mContext) { int accessibilityEnabled = 0; final String service = mContext.getPackageName() + "/" + AccessibilityService.class.getCanonicalName(); try { accessibilityEnabled = Settings.Secure.getInt( mContext.getApplicationContext().getContentResolver(), android.provider.Settings.Secure.ACCESSIBILITY_ENABLED); } catch (Settings.SettingNotFoundException e) { e.printStackTrace(); } TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':'); if (accessibilityEnabled == 1) { String settingValue = Settings.Secure.getString( mContext.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); if (settingValue != null) { mStringColonSplitter.setString(settingValue); while (mStringColonSplitter.hasNext()) { String accessibilityService = mStringColonSplitter.next(); if (accessibilityService.equalsIgnoreCase(service)) { return true; } } } } else { return false; } return false; }
Example 13
Source File: GeoEnabledConsistencyReceiverTest.java From mobile-messaging-sdk-android with Apache License 2.0 | 5 votes |
@Test public void test_shouldFirstCallIsLocationModeOn_whenVersionKitKatOrAboveAndGeoActivated() throws Settings.SettingNotFoundException { //noinspection WrongConstant Mockito.when(contextMock.getSystemService(Mockito.eq(Context.LOCATION_SERVICE))).thenReturn(locationManagerMock); Mockito.when(geoHelperSpy.isLocationModeOn(context)).thenReturn(true); Mockito.when(geoHelperSpy.isKitKatOrAbove()).thenReturn(true); PreferenceHelper.saveBoolean(context, MobileMessagingProperty.GEOFENCING_ACTIVATED, true); // When geoEnabledConsistencyReceiverWithSpy.onReceive(context, providersChangedIntent); // Then Mockito.verify(geoHelperSpy, Mockito.times(1)).isLocationModeOn(context); Mockito.verify(geoHelperSpy, Mockito.never()).isNetworkProviderAvailable(context); }
Example 14
Source File: ShellSettingsAccessor.java From test-butler with Apache License 2.0 | 5 votes |
@Override public int getInt(@NonNull String key) throws Settings.SettingNotFoundException { /* Android's Settings class does this mapping from location mode to providers. * This class bypasses the Settings class, we have to do that here too. */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q && Settings.Secure.LOCATION_MODE.equals(key)) { return locationModeSetting.getLocationMode(); } return super.getInt(key); }
Example 15
Source File: ReadBookControl.java From a with GNU General Public License v3.0 | 5 votes |
private int getScreenBrightness() { int value = 0; ContentResolver cr = MApplication.getInstance().getContentResolver(); try { value = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS); } catch (Settings.SettingNotFoundException ignored) { } return value; }
Example 16
Source File: URMUtils.java From rebootmenu with GNU General Public License v3.0 | 5 votes |
/** * 检查辅助服务是否打开 * * @param mContext 1 * @return boolean */ @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean isAccessibilitySettingsOn(@NonNull Context mContext) { //注意:不要使用以下注释掉的代码取无障碍服务开启状态!disableSelf()之后仍返回true //return ((AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled(); new DebugLog("isAccessibilitySettingsOn", DebugLog.LogLevel.V); int accessibilityEnabled = 0; final String service = mContext.getPackageName() + "/" + UnRootAccessibility.class.getCanonicalName(); try { accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED); } catch (Settings.SettingNotFoundException ignored) { } TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':'); if (accessibilityEnabled == 1) { String settingValue = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); if (settingValue != null) { mStringColonSplitter.setString(settingValue); while (mStringColonSplitter.hasNext()) { String accessibilityService = mStringColonSplitter.next(); if (accessibilityService.equalsIgnoreCase(service)) { return true; } } } } return false; }
Example 17
Source File: PermissionAccessibility.java From AcDisplay with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public boolean isGranted() { final ContentResolver cr = mContext.getContentResolver(); try { int r = Settings.Secure.getInt(cr, Settings.Secure.ACCESSIBILITY_ENABLED); if (r != 1) return false; } catch (Settings.SettingNotFoundException e) { Log.w(TAG, "Accessibility enabled setting not found!"); } final String flat = Settings.Secure.getString(cr, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES); return flat != null && flat.contains(mComponentString); }
Example 18
Source File: DetectionHelper.java From ml-authentication with Apache License 2.0 | 5 votes |
/** * Increase screen brightness by a certain rate * @param context * @param currentImageBrightness */ private static synchronized void setIncreasedScreenBrightness(Context context, double currentImageBrightness){ try { int currentScreenBrightness = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS); int increasedScreenBrightness = currentScreenBrightness + SCREEN_BRIGHTNESS_INCREASE_RATE; if (increasedScreenBrightness <= SCREEN_BRIGHTNESS_MAX){ Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, increasedScreenBrightness); Log.i(DetectionHelper.class.getName(), "setIncreasedScreenBrightness: Screen brightness has been increased: currentImageBrightness: " + currentImageBrightness + " currentScreenBrightness: " + currentScreenBrightness + " increasedScreenBrightness: " + increasedScreenBrightness); } } catch (Settings.SettingNotFoundException e) { Log.e(DetectionHelper.class.getName(), null, e); } }
Example 19
Source File: GeofencingHelper.java From mobile-messaging-sdk-android with Apache License 2.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) public boolean isLocationModeOn(Context context) throws Settings.SettingNotFoundException { int locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); return locationMode != Settings.Secure.LOCATION_MODE_OFF; }
Example 20
Source File: FloatingBallUtils.java From RelaxFinger with GNU General Public License v2.0 | 4 votes |
private static void switchRotation() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if(!checkPermissionWrite()){ return; } } //if(Build.VERSION.SDK_INT < 23) { ContentResolver resolver = context.getContentResolver(); int gravity = -1; try { gravity = Settings.System.getInt(context.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION); } catch (Settings.SettingNotFoundException e) { e.printStackTrace(); } if (gravity == 0) { //打开 Settings.System.putInt(resolver, Settings.System.ACCELEROMETER_ROTATION, 1); MyApplication.getMainThreadHandler().post(new Runnable() { @Override public void run() { Toast.makeText(context,"屏幕旋转已启用",Toast.LENGTH_SHORT).show(); } }); } else if (gravity == 1) { //关闭 Settings.System.putInt(resolver, Settings.System.ACCELEROMETER_ROTATION, 0); MyApplication.getMainThreadHandler().post(new Runnable() { @Override public void run() { Toast.makeText(context,"屏幕旋转已关闭",Toast.LENGTH_SHORT).show(); } }); } }