Java Code Examples for android.provider.Settings

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project android-bankdroid, under directory /src/com/liato/bankdroid/lockpattern/.

Source file: LockPatternUtils.java

  24 
vote

/** 
 * @return A formatted string of the next alarm (for showing on the lock screen),or null if there is no next alarm.
 */
public String getNextAlarm(){
  String nextAlarm=Settings.System.getString(mContentResolver,Settings.System.NEXT_ALARM_FORMATTED);
  if (nextAlarm == null || TextUtils.isEmpty(nextAlarm)) {
    return null;
  }
  return nextAlarm;
}
 

Example 2

From project android-context, under directory /src/edu/fsu/cs/contextprovider/.

Source file: ContextAccuracyActivity.java

  21 
vote

private void setRingtone(){
  Uri ringUri;
  String ringtone=prefs.getString(ContextConstants.PREFS_ACCURACY_POPUP_AUDIO,"Default");
  if (ringtone.equalsIgnoreCase("default"))   ringUri=Settings.System.DEFAULT_RINGTONE_URI;
 else   ringUri=Uri.parse(ringtone);
  tone=RingtoneManager.getRingtone(this,ringUri);
}
 

Example 3

From project Android-GifStitch, under directory /src/com/phunkosis/gifstitch/views/.

Source file: CameraSurface.java

  21 
vote

private void initializeScreenBrightness(){
  Window win=this.mActivity.getWindow();
  int mode=Settings.System.getInt(this.getContext().getContentResolver(),Settings.System.SCREEN_BRIGHTNESS_MODE,Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
  if (mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
    WindowManager.LayoutParams winParams=win.getAttributes();
    winParams.screenBrightness=DEFAULT_CAMERA_BRIGHTNESS;
    win.setAttributes(winParams);
  }
}
 

Example 4

From project android_packages_apps_cmparts, under directory /src/com/cyanogenmod/cmparts/activities/.

Source file: ApplicationActivity.java

  21 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  mPm=IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
  if (mPm == null) {
    Log.wtf(LOG_TAG,"Unable to get PackageManager!");
  }
  setTitle(R.string.application_settings_title_subhead);
  addPreferencesFromResource(R.xml.application_settings);
  PreferenceScreen prefSet=getPreferenceScreen();
  mInstallLocationPref=(ListPreference)prefSet.findPreference(INSTALL_LOCATION_PREF);
  String installLocation="0";
  try {
    installLocation=String.valueOf(mPm.getInstallLocation());
  }
 catch (  RemoteException e) {
    Log.e(LOG_TAG,"Unable to get default install location!",e);
  }
  mInstallLocationPref.setValue(installLocation);
  mInstallLocationPref.setOnPreferenceChangeListener(this);
  mSwitchStoragePref=(CheckBoxPreference)prefSet.findPreference(SWITCH_STORAGE_PREF);
  mSwitchStoragePref.setChecked((SystemProperties.getInt("persist.sys.vold.switchexternal",0) == 1));
  if (SystemProperties.get("ro.vold.switchablepair","").equals("")) {
    mSwitchStoragePref.setSummaryOff(R.string.pref_storage_switch_unavailable);
    mSwitchStoragePref.setEnabled(false);
  }
  mMoveAllAppsPref=(CheckBoxPreference)prefSet.findPreference(MOVE_ALL_APPS_PREF);
  mMoveAllAppsPref.setChecked(Settings.Secure.getInt(getContentResolver(),Settings.Secure.ALLOW_MOVE_ALL_APPS_EXTERNAL,0) == 1);
  mEnableManagement=(CheckBoxPreference)prefSet.findPreference(ENABLE_PERMISSIONS_MANAGEMENT);
  mEnableManagement.setChecked(Settings.Secure.getInt(getContentResolver(),Settings.Secure.ENABLE_PERMISSIONS_MANAGEMENT,getResources().getBoolean(com.android.internal.R.bool.config_enablePermissionsManagement) ? 1 : 0) == 1);
  mEnableManagement.setOnPreferenceChangeListener(this);
}
 

Example 5

From project android-marvin, under directory /marvin/src/main/java/de/akquinet/android/marvin/util/.

Source file: MarvinConnectivityUtil.java

  20 
vote

public static void setAirplaneMode(Context context,boolean newStatus){
  boolean airplaneModeOn=isAirplaneModeOn(context);
  if (airplaneModeOn && newStatus) {
    return;
  }
  if (!airplaneModeOn && !newStatus) {
    return;
  }
  if (airplaneModeOn && !newStatus) {
    Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,0);
    Intent intent=new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
    intent.putExtra("state",0);
    context.sendBroadcast(intent);
    return;
  }
  if (!airplaneModeOn && newStatus) {
    Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,1);
    Intent intent=new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
    intent.putExtra("state",1);
    context.sendBroadcast(intent);
    return;
  }
}
 

Example 6

From project android-thaiime, under directory /inputmethodcommon/src/com/android/inputmethodcommon/.

Source file: InputMethodSettingsImpl.java

  20 
vote

/** 
 * Initialize internal states of this object.
 * @param context the context for this application.
 * @param prefScreen a PreferenceScreen of PreferenceActivity or PreferenceFragment.
 * @return true if this application is an IME and has two or more subtypes, false otherwise.
 */
public boolean init(final Context context,final PreferenceScreen prefScreen){
  mContext=context;
  mImm=(InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
  mImi=getMyImi(context,mImm);
  if (mImi == null || mImi.getSubtypeCount() <= 1) {
    return false;
  }
  mSubtypeEnablerPreference=new Preference(context);
  mSubtypeEnablerPreference.setOnPreferenceClickListener(new OnPreferenceClickListener(){
    @Override public boolean onPreferenceClick(    Preference preference){
      final CharSequence title=getSubtypeEnablerTitle(context);
      final Intent intent=new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
      intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID,mImi.getId());
      if (!TextUtils.isEmpty(title)) {
        intent.putExtra(Intent.EXTRA_TITLE,title);
      }
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
      context.startActivity(intent);
      return true;
    }
  }
);
  prefScreen.addPreference(mSubtypeEnablerPreference);
  updateSubtypeEnabler();
  return true;
}
 

Example 7

From project android-voip-service, under directory /src/main/java/org/linphone/.

Source file: LinphoneManager.java

  20 
vote

public void playDtmf(ContentResolver r,char dtmf){
  try {
    if (Settings.System.getInt(r,Settings.System.DTMF_TONE_WHEN_DIALING) == 0) {
      return;
    }
  }
 catch (  SettingNotFoundException e) {
  }
  getLc().playDtmf(dtmf,-1);
}
 

Example 8

From project AndroidBillingLibrary, under directory /AndroidBillingLibrary/src/net/robotmedia/billing/utils/.

Source file: Security.java

  20 
vote

private static AESObfuscator getObfuscator(Context context,byte[] salt){
  if (_obfuscator == null) {
    final String installationId=Installation.id(context);
    final String deviceId=Settings.Secure.getString(context.getContentResolver(),Settings.Secure.ANDROID_ID);
    final String password=installationId + deviceId + context.getPackageName();
    _obfuscator=new AESObfuscator(salt,password);
  }
  return _obfuscator;
}
 

Example 9

From project AndroidCommon, under directory /src/com/asksven/android/common/settings/.

Source file: GpsSettings.java

  20 
vote

@TargetApi(8) public static void turnGPSOn(Context context){
  String provider=Settings.Secure.getString(context.getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
  Settings.Secure.setLocationProviderEnabled(context.getContentResolver(),"gps",true);
  if (!provider.contains("gps")) {
    final Intent poke=new Intent();
    poke.setClassName("com.android.settings","com.android.settings.widget.SettingsAppWidgetProvider");
    poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
    poke.setData(Uri.parse("3"));
    context.sendBroadcast(poke);
  }
}
 

Example 10

From project androidtracks, under directory /src/org/sfcta/cycletracks/.

Source file: MainInput.java

  20 
vote

private void buildAlertMessageNoGps(){
  final AlertDialog.Builder builder=new AlertDialog.Builder(this);
  builder.setMessage("Your phone's GPS is disabled. CycleTracks needs GPS to determine your location.\n\nGo to System Settings now to enable GPS?").setCancelable(false).setPositiveButton("GPS Settings...",new DialogInterface.OnClickListener(){
    public void onClick(    final DialogInterface dialog,    final int id){
      final ComponentName toLaunch=new ComponentName("com.android.settings","com.android.settings.SecuritySettings");
      final Intent intent=new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
      intent.addCategory(Intent.CATEGORY_LAUNCHER);
      intent.setComponent(toLaunch);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivityForResult(intent,0);
    }
  }
).setNegativeButton("Cancel",new DialogInterface.OnClickListener(){
    public void onClick(    final DialogInterface dialog,    final int id){
      dialog.cancel();
    }
  }
);
  final AlertDialog alert=builder.create();
  alert.show();
}
 

Example 11

From project android_7, under directory /src/org/immopoly/android/helper/.

Source file: LocationHelper.java

  20 
vote

public static void requestLocationSettings(final Context context){
  AlertDialog.Builder builder=new AlertDialog.Builder(context);
  builder.setTitle(R.string.allow_localization_title);
  builder.setMessage(R.string.allow_localization_message);
  builder.setCancelable(true).setNegativeButton(R.string.button_cancel,new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int id){
    }
  }
);
  final Intent locationSettingsIntent=new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  final ComponentName toLaunch=new ComponentName("com.android.settings","com.android.settings.SecuritySettings");
  locationSettingsIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  locationSettingsIntent.setComponent(toLaunch);
  locationSettingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  final Intent generellSettingsIntent=new Intent(Settings.ACTION_SETTINGS);
  builder.setPositiveButton("Einstellungen",new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int id){
      if (context.getPackageManager().resolveActivity(locationSettingsIntent,PackageManager.MATCH_DEFAULT_ONLY) != null) {
        context.startActivity(locationSettingsIntent);
      }
 else       if (context.getPackageManager().resolveActivity(generellSettingsIntent,PackageManager.MATCH_DEFAULT_ONLY) != null) {
        context.startActivity(generellSettingsIntent);
      }
 else {
        Toast.makeText(context,context.getString(R.string.allow_localization_message_manuel),Toast.LENGTH_LONG).show();
      }
    }
  }
);
  AlertDialog alert=builder.create();
  alert.show();
}
 

Example 12

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/.

Source file: AccessibilitySettings.java

  20 
vote

@Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,Preference preference){
  final String key=preference.getKey();
  if (TOGGLE_ACCESSIBILITY_SERVICE_CHECKBOX.equals(key)) {
    boolean isChecked=((CheckBoxPreference)preference).isChecked();
    handleEnableAccessibilityStateChange((CheckBoxPreference)preference);
  }
 else   if (POWER_BUTTON_ENDS_CALL_CHECKBOX.equals(key)) {
    boolean isChecked=((CheckBoxPreference)preference).isChecked();
    Settings.Secure.putInt(getContentResolver(),Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,(isChecked ? Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP : Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_SCREEN_OFF));
  }
 else   if (preference instanceof CheckBoxPreference) {
    handleEnableAccessibilityServiceStateChange((CheckBoxPreference)preference);
  }
  return super.onPreferenceTreeClick(preferenceScreen,preference);
}
 

Example 13

From project android_packages_apps_CMSettings, under directory /src/com/cyanogenmod/settings/activities/.

Source file: Backlight.java

  20 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.backlight_settings);
  PreferenceScreen prefSet=getPreferenceScreen();
  ContentResolver cr=getContentResolver();
  mFilterEnabled=(CheckBoxPreference)prefSet.findPreference(FILTER_ENABLED);
  mFilterEnabled.setChecked(Settings.System.getInt(cr,Settings.System.LIGHT_FILTER,0) != 0);
  mFilterEnabled.setOnPreferenceChangeListener(this);
  mFilterReset=(ListPreference)prefSet.findPreference(FILTER_RESET);
  mFilterReset.setValue(String.valueOf(Settings.System.getInt(cr,Settings.System.LIGHT_FILTER_RESET,-1)));
  mFilterReset.setOnPreferenceChangeListener(this);
  mFilterWindow=(ListPreference)prefSet.findPreference(FILTER_WINDOW);
  mFilterWindow.setValue(String.valueOf(Settings.System.getInt(cr,Settings.System.LIGHT_FILTER_WINDOW,30000)));
  mFilterWindow.setOnPreferenceChangeListener(this);
  mFilterInterval=(ListPreference)prefSet.findPreference(FILTER_INTERVAL);
  mFilterInterval.setValue(String.valueOf(Settings.System.getInt(cr,Settings.System.LIGHT_FILTER_INTERVAL,1000)));
  mFilterInterval.setOnPreferenceChangeListener(this);
  mLevelsEnabled=(CheckBoxPreference)prefSet.findPreference(LEVELS_ENABLED);
  mLevelsEnabled.setChecked(Settings.System.getInt(cr,Settings.System.LIGHT_SENSOR_CUSTOM,0) != 0);
  mLevelsEnabled.setOnPreferenceChangeListener(this);
  mScreenDim=(ListPreference)prefSet.findPreference(SCREEN_DIM);
  mScreenDim.setValue(String.valueOf(Settings.System.getInt(cr,Settings.System.LIGHT_SCREEN_DIM,android.os.Power.BRIGHTNESS_DIM)));
  mScreenDim.setOnPreferenceChangeListener(this);
  mDecreaseEnabled=(CheckBoxPreference)prefSet.findPreference(DECREASE_ENABLED);
  mDecreaseEnabled.setChecked(Settings.System.getInt(cr,Settings.System.LIGHT_DECREASE,0) != 0);
  mDecreaseEnabled.setOnPreferenceChangeListener(this);
  mDecreaseHysteresis=(ListPreference)prefSet.findPreference(DECREASE_HYSTERESIS);
  mDecreaseHysteresis.setValue(String.valueOf(Settings.System.getInt(cr,Settings.System.LIGHT_HYSTERESIS,50)));
  mDecreaseHysteresis.setOnPreferenceChangeListener(this);
}
 

Example 14

From project android_packages_apps_Nfc, under directory /src/com/android/nfc/.

Source file: NfcService.java

  20 
vote

void registerForAirplaneMode(IntentFilter filter){
  final ContentResolver resolver=mContext.getContentResolver();
  final String airplaneModeRadios=Settings.System.getString(resolver,Settings.System.AIRPLANE_MODE_RADIOS);
  final String toggleableRadios=Settings.System.getString(resolver,Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
  mIsAirplaneSensitive=airplaneModeRadios == null ? true : airplaneModeRadios.contains(Settings.System.RADIO_NFC);
  mIsAirplaneToggleable=toggleableRadios == null ? false : toggleableRadios.contains(Settings.System.RADIO_NFC);
  if (mIsAirplaneSensitive) {
    filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
  }
}
 

Example 15

From project android_packages_apps_phone, under directory /src/com/android/phone/.

Source file: BluetoothHeadsetService.java

  20 
vote

public int getPriority(BluetoothDevice device){
  enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,"Need BLUETOOTH_ADMIN permission");
synchronized (BluetoothHeadsetService.this) {
    int priority=Settings.Secure.getInt(getContentResolver(),Settings.Secure.getBluetoothHeadsetPriorityKey(device.getAddress()),BluetoothHeadset.PRIORITY_UNDEFINED);
    return priority;
  }
}
 

Example 16

From project android_packages_apps_SalvageParts, under directory /src/com/salvagemod/salvageparts/activities/.

Source file: LockscreenStyleActivity.java

  20 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setTitle(R.string.lockscreen_settings_title_subhead);
  addPreferencesFromResource(R.xml.lockscreen_style_settings);
  PreferenceScreen prefSet=getPreferenceScreen();
  mLockscreenStylePref=(ListPreference)prefSet.findPreference(LOCKSCREEN_STYLE_PREF);
  int lockscreenStyle=Settings.System.getInt(getContentResolver(),Settings.System.LOCKSCREEN_STYLE_PREF,1);
  mLockscreenStylePref.setValue(String.valueOf(lockscreenStyle));
  mLockscreenStylePref.setOnPreferenceChangeListener(this);
  mRotaryUnlockDownToggle=(CheckBoxPreference)prefSet.findPreference(LOCKSCREEN_ROTARY_UNLOCK_DOWN_TOGGLE);
  mRotaryUnlockDownToggle.setChecked(Settings.System.getInt(getContentResolver(),Settings.System.LOCKSCREEN_ROTARY_UNLOCK_DOWN,0) == 1);
  mRotaryHideArrowsToggle=(CheckBoxPreference)prefSet.findPreference(LOCKSCREEN_ROTARY_HIDE_ARROWS_TOGGLE);
  mRotaryHideArrowsToggle.setChecked(Settings.System.getInt(getContentResolver(),Settings.System.LOCKSCREEN_ROTARY_HIDE_ARROWS,0) == 1);
  mCustomAppTogglePref=(CheckBoxPreference)prefSet.findPreference(LOCKSCREEN_CUSTOM_APP_TOGGLE);
  mCustomAppTogglePref.setChecked(Settings.System.getInt(getContentResolver(),Settings.System.LOCKSCREEN_CUSTOM_APP_TOGGLE,0) == 1);
  mCustomIconStyle=(CheckBoxPreference)prefSet.findPreference(LOCKSCREEN_CUSTOM_ICON_STYLE);
  mCustomIconStyle.setChecked(Settings.System.getInt(getContentResolver(),Settings.System.LOCKSCREEN_CUSTOM_ICON_STYLE,1) == 2);
  updateStylePrefs(lockscreenStyle);
  mCustomAppActivityPref=(Preference)prefSet.findPreference(LOCKSCREEN_CUSTOM_APP_ACTIVITY);
}