android.provider.Settings.SettingNotFoundException Java Examples

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: PermissionManager.java    From FimiX8-RE with MIT License 6 votes vote down vote up
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;
    }
}
 
Example #2
Source File: BackgroundGeolocationFacade.java    From background-geolocation-android with Apache License 2.0 6 votes vote down vote up
public boolean locationServicesEnabled() throws PluginException {
    Context context = getContext();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        int locationMode = 0;
        try {
            locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
            return locationMode != Settings.Secure.LOCATION_MODE_OFF;
        } catch (SettingNotFoundException e) {
            logger.error("Location services check failed", e);
            throw new PluginException("Location services check failed", e, PluginException.SETTINGS_ERROR);
        }
    } else {
        String locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        return !TextUtils.isEmpty(locationProviders);
    }
}
 
Example #3
Source File: AccessibilityServiceHelper.java    From ViewDebugHelper with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static boolean isAccessibilitySettingsOn(Context context, String serviceName) {
    int accessibilityEnabled = 0;
    boolean accessibilityFound = false;
    try {
        accessibilityEnabled = Settings.Secure.getInt(context.getApplicationContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED);
    } catch (SettingNotFoundException e) {
    }
    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
    if (accessibilityEnabled == 1) {
        String settingValue = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
        if (settingValue != null) {
            TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
            splitter.setString(settingValue);
            while (splitter.hasNext()) {
                String accessabilityService = splitter.next();
                if (accessabilityService.equalsIgnoreCase(serviceName)) {
                    return true;
                }
            }
        }
    } else {
        // Log.v(TAG, "***ACCESSIBILIY IS DISABLED***");
    }

    return accessibilityFound;
}
 
Example #4
Source File: Helper.java    From Learning-Resources with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: ConfirmationPrompt.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private int getUiOptionsAsFlags() {
    int uiOptionsAsFlags = 0;
    try {
        ContentResolver contentResolver = mContext.getContentResolver();
        int inversionEnabled = Settings.Secure.getInt(contentResolver,
                Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
        if (inversionEnabled == 1) {
            uiOptionsAsFlags |= UI_OPTION_ACCESSIBILITY_INVERTED_FLAG;
        }
        float fontScale = Settings.System.getFloat(contentResolver,
                Settings.System.FONT_SCALE);
        if (fontScale > 1.0) {
            uiOptionsAsFlags |= UI_OPTION_ACCESSIBILITY_MAGNIFIED_FLAG;
        }
    } catch (SettingNotFoundException e) {
        Log.w(TAG, "Unexpected SettingNotFoundException");
    }
    return uiOptionsAsFlags;
}
 
Example #7
Source File: AccessibilityServiceHelper.java    From RedEnvelopeAssistant with MIT License 5 votes vote down vote up
public static boolean isAccessibilitySettingsOn(Context context) {
	int accessibilityEnabled = 0;
	final String service = context.getPackageName() + "/" + WechatAccService.class.getName();
	boolean accessibilityFound = false;
	try {
		accessibilityEnabled = Settings.Secure.getInt(context.getApplicationContext().getContentResolver(), android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
	} catch (SettingNotFoundException e) {
	}
	TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
	if (accessibilityEnabled == 1) {
		String settingValue = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
		if (settingValue != null) {
			TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
			splitter.setString(settingValue);
			while (splitter.hasNext()) {
				String accessabilityService = splitter.next();
				if (accessabilityService.equalsIgnoreCase(service)) {
					return true;
				}
			}
		}
	} else {
		// Log.v(TAG, "***ACCESSIBILIY IS DISABLED***");
	}

	return accessibilityFound;
}
 
Example #8
Source File: ControlLightness.java    From dttv-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: NotificationAccessibilityService.java    From OpenFit with MIT License 5 votes vote down vote up
public static boolean isAccessibilitySettingsOn(Context mContext) {
    int accessibilityEnabled = 0;
    final String service = "com.mytest.accessibility/com.mytest.accessibility.MyAccessibilityService";
    
    Log.v(LOG_TAG, "Looking for accessibility");
    boolean accessibilityFound = false;
    try {
        accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(), android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
        Log.d(LOG_TAG, "accessibilityEnabled = " + accessibilityEnabled);
    }
    catch (SettingNotFoundException e) {
        Log.e(LOG_TAG, "Error finding setting, default accessibility to not found: " + e.getMessage());
    }
    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
 
    if(accessibilityEnabled == 1) {
        Log.d(LOG_TAG, "***ACCESSIBILIY IS ENABLED*** -----------------");
        String settingValue = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
        if(settingValue != null) {
            TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
            splitter.setString(settingValue);
            while(splitter.hasNext()) {
                String accessabilityService = splitter.next();
                 
                Log.d(LOG_TAG, "-------------- > accessabilityService :: " + accessabilityService);
                if (accessabilityService.equalsIgnoreCase(service)) {
                    Log.v(LOG_TAG, "We've found the correct setting - accessibility is switched on!");
                    return true;
                }
            }
        }
    }
    else {
        Log.v(LOG_TAG, "***ACCESSIBILIY IS DISABLED***");
    }
             
    return accessibilityFound;
}
 
Example #10
Source File: ImportantNoticeUtils.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
static boolean isInSystemSetupWizard(final Context context) {
    try {
        final int userSetupComplete = Settings.Secure.getInt(
                context.getContentResolver(), Settings_Secure_USER_SETUP_COMPLETE);
        return userSetupComplete == USER_SETUP_IS_NOT_COMPLETE;
    } catch (final SettingNotFoundException e) {
        Log.w(TAG, "Can't find settings in Settings.Secure: key="
                + Settings_Secure_USER_SETUP_COMPLETE);
        return false;
    }
}
 
Example #11
Source File: Utilities.java    From LiveBlurListView with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #12
Source File: AndroidUtil.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
/**
 * 判断是否开启了自动亮度调节
 * 
 * @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;
}
 
Example #13
Source File: AndroidUtil.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前屏幕亮度,范围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;
}
 
Example #14
Source File: BasePlayController.java    From letv with Apache License 2.0 5 votes vote down vote up
private int getScreenBrightness() {
    int screenBrightness = 255;
    try {
        screenBrightness = System.getInt(getActivity().getContentResolver(), "screen_brightness");
    } catch (SettingNotFoundException e) {
    }
    return screenBrightness;
}
 
Example #15
Source File: ImportantNoticeUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
@UsedForTesting
static boolean isInSystemSetupWizard(final Context context) {
    try {
        final int userSetupComplete = Settings.Secure.getInt(
                context.getContentResolver(), Settings_Secure_USER_SETUP_COMPLETE);
        return userSetupComplete == USER_SETUP_IS_NOT_COMPLETE;
    } catch (final SettingNotFoundException e) {
        Log.w(TAG, "Can't find settings in Settings.Secure: key="
                + Settings_Secure_USER_SETUP_COMPLETE);
        return false;
    }
}
 
Example #16
Source File: ScreenUtilsTest.java    From android-utilset with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSetScreenOfTimeout() throws SettingNotFoundException {
	int timeout = 15000;
	ScreenUtils.setScreenOffTimeout(context, timeout);

	int timeoutFromSettings = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT);
	
	assertThat(timeoutFromSettings, is(timeout));
}
 
Example #17
Source File: EnergyWrapper.java    From stynico with MIT License 5 votes vote down vote up
public int getWiFiStatus()
   {
   	int iStatus = 0;
   	ContentResolver cr = mcontext.getContentResolver();
       try 
       {
    iStatus = Settings.Secure.getInt(cr, Settings.Secure.WIFI_ON);
       }
catch (SettingNotFoundException snfe)
{
    iStatus = 0;    }
       return iStatus;
   }
 
Example #18
Source File: EnergyWrapper.java    From stynico with MIT License 5 votes vote down vote up
public int getBluetoothStatus()
   {
   	int iStatus = 0;
   	ContentResolver cr = mcontext.getContentResolver();
       try 
       {
    iStatus = Settings.Secure.getInt(cr, Settings.Secure.BLUETOOTH_ON);
       }
catch (SettingNotFoundException snfe)
{
    iStatus = 0;    }
       return iStatus;
   }
 
Example #19
Source File: EnergyWrapper.java    From stynico with MIT License 5 votes vote down vote up
public int getBacklightTime()
   {
   	int Time = 0;    	
   	ContentResolver cr = mcontext.getContentResolver();
       try 
       {
    Time = Settings.System.getInt(cr, Settings.System.SCREEN_OFF_TIMEOUT);
       }
catch (SettingNotFoundException snfe) 
       {
    //Log.d(tag,"error()");    
       }

       return Time;
   }
 
Example #20
Source File: BluetoothManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isBleScanAlwaysAvailable() {
    if (isAirplaneModeOn() && !mEnable) {
        return false;
    }
    try {
        return Settings.Global.getInt(mContentResolver,
                Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE) != 0;
    } catch (SettingNotFoundException e) {
    }
    return false;
}
 
Example #21
Source File: EnergyWrapper.java    From stynico with MIT License 5 votes vote down vote up
public int getBrightness()
   {
   	int mOldBrightness = 0;
   	ContentResolver cr = mcontext.getContentResolver();
       try 
       {
    mOldBrightness = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS);
       }
catch (SettingNotFoundException snfe)
{
    mOldBrightness = 255;    }

       return mOldBrightness;
   }
 
Example #22
Source File: AndroidIntegration.java    From oversec with GNU General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #23
Source File: VibratorService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private boolean updateInputDeviceVibratorsLocked() {
    boolean changed = false;
    boolean vibrateInputDevices = false;
    try {
        vibrateInputDevices = Settings.System.getIntForUser(
                mContext.getContentResolver(),
                Settings.System.VIBRATE_INPUT_DEVICES, UserHandle.USER_CURRENT) > 0;
    } catch (SettingNotFoundException snfe) {
    }
    if (vibrateInputDevices != mVibrateInputDevicesSetting) {
        changed = true;
        mVibrateInputDevicesSetting = vibrateInputDevices;
    }

    if (mVibrateInputDevicesSetting) {
        if (!mInputDeviceListenerRegistered) {
            mInputDeviceListenerRegistered = true;
            mIm.registerInputDeviceListener(this, mH);
        }
    } else {
        if (mInputDeviceListenerRegistered) {
            mInputDeviceListenerRegistered = false;
            mIm.unregisterInputDeviceListener(this);
        }
    }

    mInputDeviceVibrators.clear();
    if (mVibrateInputDevicesSetting) {
        int[] ids = mIm.getInputDeviceIds();
        for (int i = 0; i < ids.length; i++) {
            InputDevice device = mIm.getInputDevice(ids[i]);
            Vibrator vibrator = device.getVibrator();
            if (vibrator.hasVibrator()) {
                mInputDeviceVibrators.add(vibrator);
            }
        }
        return true;
    }
    return changed;
}
 
Example #24
Source File: VibratorService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private int runVibrate() {
    Trace.traceBegin(Trace.TRACE_TAG_VIBRATOR, "runVibrate");
    try {
        try {
            final int zenMode = Settings.Global.getInt(mContext.getContentResolver(),
                    Settings.Global.ZEN_MODE);
            if (zenMode != Settings.Global.ZEN_MODE_OFF) {
                try (PrintWriter pw = getOutPrintWriter();) {
                    pw.print("Ignoring because device is on DND mode ");
                    pw.println(DebugUtils.flagsToString(Settings.Global.class, "ZEN_MODE_",
                            zenMode));
                    return 0;
                }
            }
        } catch (SettingNotFoundException e) {
            // ignore
        }

        final long duration = Long.parseLong(getNextArgRequired());
        if (duration > MAX_VIBRATION_MS) {
            throw new IllegalArgumentException("maximum duration is " + MAX_VIBRATION_MS);
        }
        String description = getNextArg();
        if (description == null) {
            description = "Shell command";
        }

        VibrationEffect effect =
                VibrationEffect.createOneShot(duration, VibrationEffect.DEFAULT_AMPLITUDE);
        vibrate(Binder.getCallingUid(), description, effect, AudioAttributes.USAGE_UNKNOWN,
                mToken);
        return 0;
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_VIBRATOR);
    }
}
 
Example #25
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void incrementBootCount() {
    synchronized (mLock) {
        int count;
        try {
            count = Settings.Global.getInt(
                    getContext().getContentResolver(), Settings.Global.BOOT_COUNT);
        } catch (SettingNotFoundException e) {
            count = 0;
        }
        Settings.Global.putInt(
                getContext().getContentResolver(), Settings.Global.BOOT_COUNT, count + 1);
    }
}
 
Example #26
Source File: InputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private int getPointerSpeedSetting() {
    int speed = InputManager.DEFAULT_POINTER_SPEED;
    try {
        speed = Settings.System.getIntForUser(mContext.getContentResolver(),
                Settings.System.POINTER_SPEED, UserHandle.USER_CURRENT);
    } catch (SettingNotFoundException snfe) {
    }
    return speed;
}
 
Example #27
Source File: InputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private int getShowTouchesSetting(int defaultValue) {
    int result = defaultValue;
    try {
        result = Settings.System.getIntForUser(mContext.getContentResolver(),
                Settings.System.SHOW_TOUCHES, UserHandle.USER_CURRENT);
    } catch (SettingNotFoundException snfe) {
    }
    return result;
}
 
Example #28
Source File: ConfirmationPrompt.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #29
Source File: CardEmulation.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns whether the user has allowed AIDs registered in the
 * specified category to be handled by a service that is preferred
 * by the foreground application, instead of by a pre-configured default.
 *
 * Foreground applications can set such preferences using the
 * {@link #setPreferredService(Activity, ComponentName)} method.
 *
 * @param category The category, e.g. {@link #CATEGORY_PAYMENT}
 * @return whether AIDs in the category can be handled by a service
 *         specified by the foreground app.
 */
public boolean categoryAllowsForegroundPreference(String category) {
    if (CATEGORY_PAYMENT.equals(category)) {
        boolean preferForeground = false;
        try {
            preferForeground = Settings.Secure.getInt(mContext.getContentResolver(),
                    Settings.Secure.NFC_PAYMENT_FOREGROUND) != 0;
        } catch (SettingNotFoundException e) {
        }
        return preferForeground;
    } else {
        // Allowed for all other categories
        return true;
    }
}
 
Example #30
Source File: DownloadManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns maximum size, in bytes, of downloads that may go over a mobile connection; or null if
 * there's no limit
 *
 * @param context the {@link Context} to use for accessing the {@link ContentResolver}
 * @return maximum size, in bytes, of downloads that may go over a mobile connection; or null if
 * there's no limit
 */
public static Long getMaxBytesOverMobile(Context context) {
    try {
        return Settings.Global.getLong(context.getContentResolver(),
                Settings.Global.DOWNLOAD_MAX_BYTES_OVER_MOBILE);
    } catch (SettingNotFoundException exc) {
        return null;
    }
}