List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
/** * Reads a Bitmap from an Uri./*from w ww.java 2 s . co m*/ * * @param context * @param selectedImage * @return Bitmap */ public static Bitmap readBitmap(Context context, Uri selectedImage) { Bitmap bm = null; BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.RGB_565; options.inScaled = false; // options.inSampleSize = 3; AssetFileDescriptor fileDescriptor = null; try { fileDescriptor = context.getContentResolver().openAssetFileDescriptor(selectedImage, "r"); } catch (FileNotFoundException e) { return null; } finally { try { bm = BitmapFactory.decodeFileDescriptor(fileDescriptor.getFileDescriptor(), null, options); fileDescriptor.close(); } catch (IOException e) { return null; } } return bm; }
From source file:Main.java
private static void deleteFileForMediaStore(Context mContext, File file) { // Match on the file path String selection = MediaStore.Images.Media.DATA + " = ?"; String[] selectionArgs = new String[] { file.getAbsolutePath() }; // Query for the ID of the media matching the file path Uri queryUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; ContentResolver contentResolver = mContext.getContentResolver(); contentResolver.delete(queryUri, selection, selectionArgs); }
From source file:Main.java
public static void insertImage2MediaStore(Context context, String path) { File f = new File(path); if (f != null && f.exists()) { ContentValues values = new ContentValues(); values.put(Media.DISPLAY_NAME, f.getName()); values.put(Media.DESCRIPTION, f.getName()); values.put(Media.MIME_TYPE, "image/jpeg"); values.put(Media.DATA, path); Uri uri = context.getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values); }/*from w w w .j av a 2 s . c om*/ }
From source file:Main.java
private static UUID getUuid(Context c) { final SharedPreferences prefs = c.getSharedPreferences(ID_PREFS_FILE, Context.MODE_PRIVATE); final String id = prefs.getString(ID_PREFS_DEVICE_ID, null); final UUID uuid; if (id != null) { uuid = UUID.fromString(id); } else {/*from w w w.j a v a 2 s .co m*/ final String androidId = Secure.getString(c.getContentResolver(), Secure.ANDROID_ID); try { if (!BAD_UUID.equals(androidId)) { uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8")); } else { final String deviceId = ((TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE)) .getDeviceId(); if (deviceId != null) uuid = UUID.nameUUIDFromBytes(deviceId.getBytes("utf8")); else uuid = UUID.randomUUID(); } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } prefs.edit().putString(ID_PREFS_DEVICE_ID, uuid.toString()).commit(); } return uuid; }
From source file:com.njlabs.amrita.aid.util.Identifier.java
@SuppressLint("HardwareIds") public static String identify(Context context) { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); final String tmDevice, tmSerial, androidId; tmDevice = "" + tm.getDeviceId(); tmSerial = "" + tm.getSimSerialNumber(); androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); return deviceUuid.toString(); }
From source file:com.nbos.phonebook.sync.platform.ContactManager.java
public static void resetDirtySharedBooks(Context ctx) { ContentResolver cr = ctx.getContentResolver(); int num = cr.delete(Constants.SHARE_BOOK_URI, BookTable.DELETED + " = 1", null); Log.i(tag, "Deleted " + num + " contacts sharing with"); ContentValues values = new ContentValues(); values = new ContentValues(); values.put(BookTable.DIRTY, "0"); num = cr.update(Constants.SHARE_BOOK_URI, values, null, null); Log.i(tag, "Updated " + num + " sharebooks to dirty = 0"); }
From source file:hobby.wei.c.phone.Network.java
@SuppressWarnings("deprecation") public static boolean isAirplaneModeOn(Context context) { return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0; }
From source file:com.nbos.phonebook.sync.platform.ContactManager.java
public static void resetDirtyGroups(Context ctx) { ContentResolver cr = ctx.getContentResolver(); ContentValues values = new ContentValues(); values.put(ContactsContract.Groups.DIRTY, "0"); int num = cr.update(ContactsContract.Groups.CONTENT_URI, values, null, null); Log.i(tag, "Updated " + num + " groups to dirty = 0"); num = cr.delete(SyncManager.addCallerIsSyncAdapterParameter(Groups.CONTENT_URI), Groups.DELETED + " = 1 " + " and " + Groups.ACCOUNT_TYPE + " = ? ", new String[] { Constants.ACCOUNT_TYPE }); Log.i(tag, "Deleted " + num + " groups"); }
From source file:net.kourlas.voipms_sms.Utils.java
/** * Gets a URI pointing to a contact's photo, given the URI for that contact. * * @param applicationContext The application context. * @param uri The URI of the contact. * @return a URI pointing to the contact's photo. *//*from www . j a v a 2 s. c o m*/ public static String getContactPhotoUri(Context applicationContext, Uri uri) { Cursor cursor = applicationContext.getContentResolver().query(uri, new String[] { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.PHOTO_THUMBNAIL_URI }, null, null, null); if (cursor.moveToFirst()) { String photoUri = cursor .getString(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI)); cursor.close(); return photoUri; } else { cursor.close(); return null; } }
From source file:eu.e43.impeller.Utils.java
public static JSONObject findPost(Context ctx, Content.Uris uris, JSONObject object) throws JSONException { Cursor res = ctx.getContentResolver().query(uris.activitiesUri, new String[] { "_json" }, "actor=? AND verb='post' AND object.id=?", new String[] { object.getJSONObject("author").getString("id"), object.getString("id") }, null); try {/* ww w . j av a 2s . c o m*/ if (res.getCount() > 0) { res.moveToFirst(); return new JSONObject(res.getString(0)); } else { return null; } } finally { res.close(); } }