List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:com.project.utilities.Utilities.java
public static String getDeviceUID(Context context) { String uid = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); return uid;/*w w w. j a v a2 s . c o m*/ }
From source file:Main.java
public static Cursor getAllCallLogAboutACaller(Context context, String callerNumber) { // cancello la chiamata in uscita se nelle preferenze ? settata tale opzione Uri delUri = Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, ""); Cursor cursor = context.getContentResolver().query(delUri, null, android.provider.CallLog.Calls.NUMBER + "=?", new String[] { "404" }, null); try {/* w w w . j a va 2s. c o m*/ boolean moveToFirst = cursor.moveToFirst(); Log.i("MOVETOFIRST", "moveToFirst=" + moveToFirst); do { int numberColumn = cursor.getColumnIndex(android.provider.CallLog.Calls.NUMBER); String callerPhoneNumber = cursor.getString(numberColumn); Log.i(TAG, "numero : " + callerPhoneNumber); } while (cursor.moveToNext()); } catch (Exception e) { Log.e(TAG, "Problem moving to first entry", e); } return cursor; }
From source file:Main.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null;//from w w w .j a v a 2 s. com String column = MediaStore.Images.Media.DATA; String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:Main.java
public static Cursor query(final Context context, Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder, final int limit) { try {//from ww w. j a v a2 s.co m final ContentResolver resolver = context.getContentResolver(); if (resolver == null) { return null; } if (limit > 0) { uri = uri.buildUpon().appendQueryParameter("limit", "" + limit).build(); } return resolver.query(uri, projection, selection, selectionArgs, sortOrder); } catch (final UnsupportedOperationException ex) { return null; } }
From source file:Main.java
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null;// ww w . ja v a 2s . co m String column = MediaStore.Images.Media.DATA; String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } finally { if (cursor != null && !cursor.isClosed()) cursor.close(); } return null; }
From source file:Main.java
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null;/*from ww w.j a v a2s . c om*/ String column = MediaStore.Images.Media.DATA; String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:Main.java
/** * Get the value of the data column for this Uri. This is useful for * MediaStore Uris, and other file-based ContentProviders. * * @param context The context./*w ww.ja va2 s . c om*/ * @param uri The Uri to query. * @param selection (Optional) Filter used in the query. * @param selectionArgs (Optional) Selection arguments used in the query. * @return The value of the _data column, which is typically a file path. */ public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(column); return cursor.getString(column_index); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:Main.java
private static int getOrientation(Context context, Uri photoUri) { /* it's on the external media. */ Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor.getCount() != 1) { return -1; }/*from ww w . jav a 2s . c o m*/ cursor.moveToFirst(); return cursor.getInt(0); }
From source file:Main.java
public static String getGSFID(Context context) { String result;/*from ww w . j a va2s .c om*/ final Uri URI = Uri.parse("content://com.google.android.gsf.gservices"); final String ID_KEY = "android_id"; String[] params = { ID_KEY }; Cursor c = context.getContentResolver().query(URI, null, null, params, null); if (c == null || !c.moveToFirst() || c.getColumnCount() < 2) { return null; } else { result = Long.toHexString(Long.parseLong(c.getString(1))); } c.close(); return result; }
From source file:Main.java
/** * Get the contact photo from a contact URI. * * @param context The context.//from ww w. j a v a 2 s . c o m * @param contactUri The contact URI. * * @return The contact photo. */ public static Bitmap getContactPhoto(final Context context, Uri contactUri) { Bitmap bitmap = null; if (contactUri != null) { InputStream inputStream = ContactsContract.Contacts .openContactPhotoInputStream(context.getContentResolver(), contactUri); if (inputStream != null) { bitmap = BitmapFactory.decodeStream(inputStream); try { inputStream.close(); } catch (IOException e) { } } } return bitmap; }