List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
public static boolean isHapticFback(Context mContext) { try {/*from w w w . j a va 2 s. c o m*/ return Settings.System.getInt(mContext.getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED) == 1; } catch (SettingNotFoundException e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static final String getTelefone(final Context contexto, final String idContato) { ContentResolver cr = contexto.getContentResolver(); Cursor phones = cr.query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + " = " + idContato, null, null); String numero = ""; while (phones.moveToNext()) { numero = phones.getString(phones.getColumnIndex(Phone.NUMBER)); break;/*from w w w . j a v a 2 s.c o m*/ } phones.close(); return numero; }
From source file:Main.java
public static long getFileSize(Context context, Uri uri) { try {/*from w w w.j a v a 2 s .co m*/ ParcelFileDescriptor fd = context.getContentResolver().openFileDescriptor(uri, "r"); long size = fd.getStatSize(); fd.close(); return size; } catch (Throwable exception) { return 0; } }
From source file:Main.java
public static String getImageAbsolutePath(Context context, Uri uri) { Cursor cursor = MediaStore.Images.Media.query(context.getContentResolver(), uri, new String[] { MediaStore.Images.Media.DATA }); if (cursor.moveToFirst()) { return cursor.getString(0); }/*from w ww .ja v a2 s.co m*/ return null; }
From source file:Main.java
public static InputStream getStreamFromUri(Context context, Uri uriFromIntent) throws FileNotFoundException { return context.getContentResolver().openInputStream(uriFromIntent); }
From source file:Main.java
public static int getScreenTimeOut(Context mContext) { return android.provider.Settings.System.getInt(mContext.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, -1); }
From source file:Main.java
public static Uri pathToContentUri(Context context, String imagePath) { Cursor cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[] { "_id" }, "_data=? ", new String[] { imagePath }, null); if (cursor != null && cursor.moveToFirst()) { int imageFile1 = cursor.getInt(cursor.getColumnIndex("_id")); Uri values1 = Uri.parse("content://media/external/images/media"); return Uri.withAppendedPath(values1, "" + imageFile1); } else {//from ww w . ja va 2 s.c o m File imageFile = new File(imagePath); if (imageFile.exists()) { ContentValues values = new ContentValues(); values.put("_data", imagePath); Uri baseUri = Media.EXTERNAL_CONTENT_URI; return context.getContentResolver().insert(baseUri, values); } else { return null; } } }
From source file:Main.java
public static String getImagePath(Context context, String id) { String path = null;/* www . j a va 2s. c o m*/ Cursor cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, null, Media._ID + "=?", new String[] { id }, null); while (cursor.moveToNext()) { path = cursor.getString(cursor.getColumnIndex(Media.DATA)); } cursor.close(); return path; }
From source file:Main.java
private static Bitmap getIconFromUri(Context mContext, Uri uri) throws IOException { InputStream input = mContext.getContentResolver().openInputStream(uri); return BitmapFactory.decodeStream(input); }
From source file:Main.java
private static String getCoverPath(Context context, long albumId) { String path = null;/* w w w .ja v a2s . c o m*/ Cursor cursor = context.getContentResolver().query( Uri.parse("content://media/external/audio/albums/" + albumId), new String[] { "album_art" }, null, null, null); if (cursor != null) { cursor.moveToNext(); path = cursor.getString(0); cursor.close(); } return path; }