List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
/** * Gets uri query to insert calendar TUM_Campus_APP to google calendar * @param c Context/*from w w w . jav a 2 s . com*/ * @return Uri for insertion */ public static Uri addCalendar(Context c) { final ContentValues cv = buildContentValues(); Uri calUri = buildCalUri(); return c.getContentResolver().insert(calUri, cv); }
From source file:Main.java
public static String getPath(Context context, Uri uri) throws NullPointerException { final String[] projection = { MediaColumns.DATA }; final Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); final int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA); cursor.moveToFirst();//from w w w .ja va 2 s. co m return cursor.getString(column_index); }
From source file:Main.java
public static synchronized void deleteCalllogByPhone(Context context, String number) { if (TextUtils.isEmpty(number)) return;/*from w w w .j a v a 2 s .c om*/ try { Cursor cursor = context.getContentResolver().query(Calls.CONTENT_URI, null, Calls.NUMBER + "=?", new String[] { number }, Calls.DATE + " desc"); if (cursor != null) { if (cursor.moveToNext()) { long _id = cursor.getLong(cursor.getColumnIndex(Calls._ID)); context.getContentResolver().delete(Calls.CONTENT_URI, Calls._ID + "=?", new String[] { String.valueOf(_id) }); } cursor.close(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
/** * Gets the md5 hashed and upper-cased device id. * // ww w .ja va2 s. c o m * @param context * the application context. * @return The encoded device id. */ public static String getEncodedDeviceId(Context context) { String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); String hashedId; if ((androidId == null) || isEmulator()) { hashedId = md5("emulator"); } else { hashedId = md5(androidId); } if (hashedId == null) { return null; } return hashedId.toUpperCase(Locale.US); }
From source file:Main.java
public static String getRealPathFromURI(Context context, Uri contentURI) { String TAG = "PINGUINO-getRealPathFromURI"; String result;/*from w w w. j a v a 2 s . c o m*/ Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); if (cursor == null) { result = contentURI.getPath(); } else { Log.d(TAG, "cursor1:" + cursor); cursor.moveToFirst(); Log.d(TAG, "cursor2:" + cursor); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); Log.d(TAG, "idx:" + idx); result = cursor.getString(idx); Log.d(TAG, "result:" + result); cursor.close(); } return result; }
From source file:Main.java
protected static String getFileKeyName(String extension, Context context) { String keyName = null;//w w w. ja v a 2 s . c o m keyName = String.valueOf(System.currentTimeMillis()); String deviceId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); keyName = deviceId + "_" + keyName + "." + extension; return keyName; }
From source file:Main.java
/**** * Remove audio file that is existing on the device. * //from w w w .j a v a2s.c om * @param ctx * {@link Context} * @param uri * {@link Uri} of the audio file * * @throws NullPointerException * if the Uri parameter is null * */ public static boolean removeAudio(Context ctx, Uri uri) { if (uri == null) { throw new NullPointerException("Uri cannot be null"); } return (ctx.getContentResolver().delete(uri, null, null) != 0); }
From source file:Main.java
public static String getFileName(Uri uri, Context context) { String result = null;// www . j a v a 2s.com if (uri.getScheme().equals("content")) { Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); try { if (cursor != null && cursor.moveToFirst()) { result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); } } finally { if (cursor != null) { cursor.close(); } } } if (result == null) { result = uri.getPath(); int cut = result.lastIndexOf('/'); if (cut != -1) { result = result.substring(cut + 1); } } return result; }
From source file:Main.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") public static boolean isAModeEnabled(Context context) { int state = 0; try {// w w w. j av a 2s .c o m if (isJBean()) state = Settings.System.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON); else state = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON); } catch (SettingNotFoundException e) { e.printStackTrace(); } if (state == 0) return false; return true; }
From source file:Main.java
public static Cursor getContactProfile(Context context, String number) { if (TextUtils.isEmpty(number)) { return null; }//from w ww . ja v a2 s. c o m ContentResolver cr = context.getContentResolver(); Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); return cr.query(uri, CONTACT_PROJ, null, null, null); }