List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
public static void saveScreenBrightness(int paramInt, Context mContext) { if (paramInt <= 5) { paramInt = 5;//w w w.j a v a 2s . c o m } try { float f = paramInt / 100.0F * 255; Settings.System.putInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, (int) f); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
/** * @param mContext//from w ww . j a v a 2 s . c o m * @param number * @return sunrise.l String 2012-5-28 */ public static String getNameFormNumber(Context mContext, String number) { String name = null; Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, number); Cursor cur = mContext.getContentResolver().query(uri, new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); if (cur != null && cur.moveToFirst()) { int nameIndex = cur.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME); name = cur.getString(nameIndex); } cur.close(); return name; }
From source file:Main.java
public static final Bitmap getBitmapFromUri(Context context, Uri uri, int maxWidth, int maxHeight) { if (uri == null) return null; try {// ww w .jav a 2 s . c om InputStream is = context.getContentResolver().openInputStream(uri); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; // Set height and width in options, does not return an image and no resource taken BitmapFactory.decodeStream(is, null, options); int pow = 0; while (options.outHeight >> pow > maxHeight || options.outWidth >> pow > maxWidth) { pow += 1; } is.close(); is = context.getContentResolver().openInputStream(uri); options.inSampleSize = 1 << pow; options.inJustDecodeBounds = false; Bitmap bmp = BitmapFactory.decodeStream(is, null, options); return bmp; } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:Main.java
public static Bitmap decodeUriToBitmap(Context context, Uri uri) { if (context == null || uri == null) return null; Bitmap bitmap = null;/*from w w w . j a v a 2 s. c om*/ try { bitmap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri)); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } return bitmap; }
From source file:Main.java
private static InputStream openPhoto(final Context context, final Uri contactUri) { Uri photoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY); Cursor cursor = context.getContentResolver().query(photoUri, new String[] { ContactsContract.Contacts.Photo.PHOTO }, null, null, null); if (cursor == null) { return null; }/*from www. j a va2 s . c o m*/ try { if (cursor.moveToFirst()) { byte[] data = cursor.getBlob(0); if (data != null) { return new ByteArrayInputStream(data); } } } finally { cursor.close(); } return null; }
From source file:Main.java
public static String getRealPathFromURI(Context context, Uri contentUri) { Cursor cursor = null;// w ww. j ava 2 s.co m try { String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } catch (NullPointerException ex) { return ""; } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
public static String uriToFilePath(Context context, String contentUri) { if (Uri.parse(contentUri).getScheme().equals("content")) { String[] p = { MediaStore.MediaColumns.DATA }; Cursor cursor = context.getContentResolver().query(Uri.parse(contentUri), p, // which columns null, // which rows (all rows) null, // selection args (none) null); // order-by clause (ascending by name) if (cursor != null) { int iColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA); if (cursor.moveToFirst()) { return (cursor.getString(iColumn)); }//from w w w .java 2s .c o m } } if (Uri.parse(contentUri).getScheme().equals("file")) { return (Uri.parse(contentUri).getPath()); } return (null); }
From source file:Main.java
private static InputStream openDisplayPhoto(final Context context, final Uri contactUri) { Uri displayPhotoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.DISPLAY_PHOTO); try {//from ww w.j a va2 s.co m AssetFileDescriptor fd = context.getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r"); return fd.createInputStream(); } catch (IOException e) { return null; } }
From source file:Main.java
/** * Get the contact name from a URI./*w w w . j a v a2 s .co m*/ * * @param context The context. * @param contactUri The contact URI. * * @return The contact name. */ public static String getContactName(final Context context, Uri contactUri) { String name = null; if (contactUri != null) { Cursor cursor = null; try { cursor = context.getContentResolver().query(contactUri, new String[] { ContactsContract.Contacts.DISPLAY_NAME }, null, null, null); if (cursor != null && cursor.moveToFirst()) { name = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); } } finally { if (cursor != null) { cursor.close(); } } } return name; }
From source file:Main.java
/** * set the value to share config/*from w ww.ja v a 2s. c o m*/ * @param context context * @param key key of the config * @param value value of the config */ public static void set(Context context, String key, String value) { ContentValues values = new ContentValues(); values.put("key", key); values.put("value", value); try { context.getContentResolver().insert(CONTENT_URI, values); } catch (IllegalArgumentException e1) { } catch (Exception e) { Log.e("AspShareUtil", "Error while set", e); } }