List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
public static Uri getUriFromBitmap(Bitmap bitmap, Context context) { try {//from w w w .j a va 2 s .co m Uri uri = Uri .parse(MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, null, null)); return uri; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static Bitmap getBitmapFromUri(Context context, Uri uri) { Bitmap bitmap = null;//w w w. ja va2s . c om try { bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri); } catch (Exception e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static boolean isInAirplaneMode(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) return Settings.System.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0; else/*from www. j av a2 s. c om*/ return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0; }
From source file:Main.java
public static String getPathFromUri(Context context, Uri u) { String[] pojo = { MediaStore.Images.Media.DATA }; Cursor cursor = context.getContentResolver().query(u, pojo, null, null, null); String picPath = null;/*from www . j av a 2 s . co m*/ if (cursor != null) { int columnIndex = cursor.getColumnIndexOrThrow(pojo[0]); cursor.moveToFirst(); picPath = cursor.getString(columnIndex); return picPath; } return null; }
From source file:Main.java
public static Bitmap decodeUriAsBitmap(Context mContext, Uri uri) { Bitmap bitmap;/*from w w w. j a v a 2s. c o m*/ try { bitmap = BitmapFactory.decodeStream(mContext.getContentResolver().openInputStream(uri)); } catch (FileNotFoundException e) { return null; } return bitmap; }
From source file:Main.java
/** * Store a picture that has just been saved to disk in the MediaStore. * //from w w w . ja v a 2s . c o m * @param imageFile * The File of the picture * @return The Uri provided by the MediaStore. */ public static Uri storePicture(Context ctx, File imageFile, String imageName) { ContentResolver cr = ctx.getContentResolver(); imageName = imageName.substring(imageName.lastIndexOf('/') + 1); ContentValues values = new ContentValues(7); values.put(Images.Media.TITLE, imageName); values.put(Images.Media.DISPLAY_NAME, imageName); values.put(Images.Media.DESCRIPTION, ""); values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis()); values.put(Images.Media.MIME_TYPE, "image/jpeg"); values.put(Images.Media.ORIENTATION, 0); File parentFile = imageFile.getParentFile(); String path = parentFile.toString().toLowerCase(); String name = parentFile.getName().toLowerCase(); values.put(Images.ImageColumns.BUCKET_ID, path.hashCode()); values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, name); values.put("_data", imageFile.toString()); Uri uri = cr.insert(sStorageURI, values); return uri; }
From source file:Main.java
/** * Returns the ID for an album./*from w ww . ja v a 2 s. c o m*/ * * @param context The {@link Context} to use. * @param albumName The name of the album. * @param artistName The name of the artist * @return The ID for an album. */ public static final long getIdForAlbum(final Context context, final String albumName, final String artistName) { Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, new String[] { BaseColumns._ID }, AlbumColumns.ALBUM + "=? AND " + AlbumColumns.ARTIST + "=?", new String[] { albumName, artistName }, AlbumColumns.ALBUM); int id = -1; if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { id = cursor.getInt(0); } cursor.close(); cursor = null; } return id; }
From source file:Main.java
public static String getFilePathByContentResolver(Context context, Uri uri) { if (null == uri) { return null; }//from w w w .ja v a 2 s . c om Cursor c = context.getContentResolver().query(uri, null, null, null, null); String filePath = null; if (null == c) { throw new IllegalArgumentException("Query on " + uri + " returns null result."); } try { if ((c.getCount() != 1) || !c.moveToFirst()) { } else { filePath = c.getString(c.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA)); } } finally { c.close(); } return filePath; }
From source file:Main.java
public static Bitmap decodeUriAsBitmap(Context context, Uri uri) { Bitmap bitmap = null;/* w ww . j a v a2s . c om*/ try { bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri); } catch (IOException e) { e.printStackTrace(); return null; } return bitmap; }
From source file:Main.java
public static boolean isAutomicBrightness(Context context) { boolean automicBrightness = false; try {/* www. j ava2 s. co m*/ automicBrightness = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC; } catch (SettingNotFoundException e) { e.printStackTrace(); } return automicBrightness; }