Context getContentResolver - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Context getContentResolver method.

This code example shows how to use the following methods:getContentResolver, getFilesDir, openFileOutput, sendBroadcast, sleep
                    "dfrsRsFMrFpk++mSt6SoxXaMbn0LL2u1CD4PCEiQMGt+lK3/3TmRTKNs+23sYS7Ahjxj0udDAkEA" + 
                    "p57Nj65WNaWeYiOfTwKXkLj8l29H5NbaGWxPT0XkWr4PvBOFZVH/wj0/qc3CMVGnv11+DyO+QUCN" + 
                    "SqBB5aRe8g=="; 
 
    private void overrideSettings(String key, String value) throws Exception {
        assertTrue(Settings.Secure.putString(mContext.getContentResolver(), key, value));
        Thread.sleep(1000);
    } 
 
    private void overrideCert(String value) throws Exception {
        overrideSettings(PINLIST_CERTIFICATE_KEY, value);
    } 
 
    private String readPins() throws Exception {
        return IoUtils.readFileAsString(PINLIST_CONTENT_PATH);
    } 
 
    private String readCurrentVersion() throws Exception {
        return IoUtils.readFileAsString("/data/misc/keychain/metadata/version"); 
    } 

9
CodeRank
This code example shows how to use the following methods:getContentResolver, getPackageManager, getPackageName
     *            the context 
     * @return the device's ANDROID_ID, or null if it could not be determined 
     * @see Secure#ANDROID_ID 
     */ 
    public static String getAndroidId(Context context) {
        String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        if (androidId == null) {
            // this happens on 1.6 and older 
            androidId = android.provider.Settings.System.getString(context.getContentResolver(),
                    android.provider.Settings.System.ANDROID_ID);
        } 
        return androidId;
    } 
 
    /** 
     * Same as {@link #getAndroidId(Context)}, but never returns null. 
     *  
     * @param context 
     *            the context 
     * @param fallbackValue 

8
CodeRank
This code example shows how to use the following methods:getContentResolver, getSystemService
    return shouldVibrateOld(context);
  } 
 
  @SuppressLint("NewApi") 
  private boolean shouldVibrateNew(Context context) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
 
    if (vibrator == null || !vibrator.hasVibrator()) {
      return false; 
    } 
 
    boolean vibrateWhenRinging = Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing", 0) != 0;
    int ringerMode = audioManager.getRingerMode();
    if (vibrateWhenRinging) {
      return ringerMode != AudioManager.RINGER_MODE_SILENT;
    } else { 
      return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
    } 
  } 
8
CodeRank
This code example shows how to use the following methods:getContentResolver, getPackageName
	 
	private static AESObfuscator _obfuscator = null;
	 
	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;
	} 
		 
	public static String unobfuscate(Context context, byte[] salt, String obfuscated) {
		final AESObfuscator obfuscator = getObfuscator(context, salt);
		try { 
			return obfuscator.unobfuscate(obfuscated);
		} catch (ValidationException e) {
			Log.w(TAG, "Invalid obfuscated data or key");
		} 
8
CodeRank
This code example shows how to use the following methods:getContentResolver, sleep
 
    public static final String PUBKEY_KEY = "pubkey_blacklist";
    public static final String SERIAL_KEY = "serial_blacklist";
 
    private void overrideSettings(String key, String value) throws Exception {
        Settings.Secure.putString(mContext.getContentResolver(), key, value);
        Thread.sleep(1000);
    } 
 
    public void testClearBlacklistPubkey() throws Exception { 
        // clear the gservices setting for a clean slate 
        overrideSettings(PUBKEY_KEY, "");
        // read the contents of the pubkey blacklist 
        String blacklist = IoUtils.readFileAsString(PUBKEY_PATH);
        // Verify that it's empty 
        assertEquals("", blacklist);
    } 
 
    public void testSetBlacklistPubkey() throws Exception { 
        // build a new thing to blacklist 
8
CodeRank
This code example shows how to use the following methods:getContentResolver, startService
 
    @Override 
    public void onReceive(final Context context, Intent intent) {
        try { 
            // Start the load average overlay, if activated 
            ContentResolver res = context.getContentResolver();
            if (Settings.Global.getInt(res, Settings.Global.SHOW_PROCESSES, 0) != 0) {
                Intent loadavg = new Intent(context, com.android.systemui.LoadAverageService.class);
                context.startService(loadavg);
            } 
        } catch (Exception e) {
            Slog.e(TAG, "Can't start load average service", e);
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getContentResolver
 
  @Override 
  public Cursor loadInBackground() {
    if (filter != null && filter.trim().length() != 0) {
      List<String> numbers = ContactAccessor.getInstance()
          .getNumbersForThreadSearchFilter(filter, context.getContentResolver());
 
      return DatabaseFactory.getThreadDatabase(context).getFilteredConversationList(numbers);
    } else { 
      return DatabaseFactory.getThreadDatabase(context).getConversationList();
    } 
  } 
} 
7
CodeRank
This code example shows how to use the following methods:bindService, getContentResolver, getPackageManager, getSharedPreferences
 
	private final SharedPreferences mPreferences; //Preferences to store the OpenUDID
	private final Random mRandom;
	 
	private OpenUDID_manager(Context context) {
		mPreferences =  context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
		mContext = context;
		mRandom = new Random();
		mReceivedOpenUDIDs = new HashMap<String, Integer>();
	} 
	 
	@Override 
  	public void onServiceConnected(ComponentName className, IBinder service) {
		//Get the OpenUDID from the remote service 
		try { 
			//Send a random number to the service 
			android.os.Parcel data = android.os.Parcel.obtain(); 
			data.writeInt(mRandom.nextInt());
			android.os.Parcel reply = android.os.Parcel.obtain(); 
			service.transact(1, android.os.Parcel.obtain(), reply, 0);

7
CodeRank
This code example shows how to use the following methods:getContentResolver, getPackageManager, getPackageName
     *            the context 
     * @return the device's ANDROID_ID, or null if it could not be determined 
     * @see Secure#ANDROID_ID 
     */ 
    public static String getAndroidId(Context context) {
        String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        if (androidId == null) {
            // this happens on 1.6 and older 
            androidId = android.provider.Settings.System.getString(context.getContentResolver(),
                    android.provider.Settings.System.ANDROID_ID);
        } 
        return androidId;
    } 
 
    /** 
     * Same as {@link #getAndroidId(Context)}, but never returns null. 
     *  
     * @param context 
     *            the context 
     * @param fallbackValue 

8
CodeRank
This code example shows how to use the following methods:getContentResolver, getResources
    Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, personId);
    InputStream inputStream;
 
    if (Build.VERSION.SDK_INT >= 14) {
      inputStream = ContactsContract.Contacts
                    .openContactPhotoInputStream(context.getContentResolver(), uri, true);
    } else { 
      inputStream = ContactsContract.Contacts
                    .openContactPhotoInputStream(context.getContentResolver(), uri);
    } 
 
    if (inputStream != null) {
      return BitmapFactory.decodeStream(inputStream);
    } else { 
      return null; 
    } 
  } 
 
  public static PersonInfo getInstance(Context context, String phoneNumber) {
    //TODO handle empty phone numbers and other bad query states 

7
CodeRank

Related Context getContentResolver Questions & Answers:

getContentResolver Method Overview
Return a ContentResolver instance for your application's package.
See Code Examples for other Android Context Methods: