List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:com.android.utility.util.Network.java
/** * Return Aeroplane mode status/*from w w w. j a va2 s . c om*/ * * @param context Activity/Application Context * @return true if Aeroplane mode is on */ @SuppressLint("NewApi") public static boolean isAeroplanModeOn(Context context) { if (context == null) { throw new IllegalArgumentException(); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0; } else { return Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0) != 0; } }
From source file:com.doplgangr.secrecy.FileSystem.storage.java
public static Uri saveThumbnail(Context context, Uri uri, String filename) { InputStream stream = null;//from w ww. j ava2s . co m try { stream = context.getContentResolver().openInputStream(uri); java.io.File thumbpath = new java.io.File(getAbsTempFolder() + "/" + "_thumb" + filename); if (thumbpath.exists()) storage.purgeFile(thumbpath); thumbpath.createNewFile(); FileOutputStream out = new FileOutputStream(thumbpath); Bitmap bitmap = decodeSampledBitmapFromPath(getPath(context, uri), 150, 150); if (bitmap == null) { //If photo fails, try Video Util.log(getPath(context, uri)); bitmap = ThumbnailUtils.createVideoThumbnail(getPath(context, uri), MediaStore.Video.Thumbnails.MICRO_KIND); } if (bitmap == null) { out.close(); storage.purgeFile(thumbpath); return null; } bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); out.close(); return Uri.fromFile(thumbpath); } catch (Exception e) { e.printStackTrace(); } finally { if (stream != null) try { stream.close(); } catch (Exception e) { e.printStackTrace(); } } return null; }
From source file:Main.java
/** * This method gets the contact image from the phone book. * /*from w w w. ja v a 2 s. c om*/ * @param context * @param imageUri * @return Contact's image or null */ public static Bitmap getByteContactImage(Context context, String imageUri, int pixel) { if (imageUri == null) { return null; } if (imageUri != null) { try { Uri image_Uri = Uri.parse(imageUri); Bitmap bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), image_Uri); bitmap = Bitmap.createScaledBitmap(bitmap, pixel, pixel, false); return getRoundedCornerBitmap(bitmap, pixel); } catch (IOException e) { Log.e("EPollUtil", e.getLocalizedMessage()); } } 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./*from www . ja v a 2s . co m*/ * @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. */ private 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
public static String getRealPathFromURI(Uri contentUri, Context ctx) { Log.d("thong", "Uri: " + contentUri.toString()); try {/*w w w . j a va 2 s . c o m*/ String realpath = ""; String[] proj = { MediaStore.Images.Media.DATA }; //Cursor cursor = ((Activity) ctx).managedQuery(contentUri, proj, null, null, null); Cursor cursor = ctx.getContentResolver().query(contentUri, proj, null, null, null); Log.d("thong", "Column count: " + cursor.getColumnCount()); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); realpath = cursor.getString(column_index); cursor.close(); return realpath; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
private static Uri createImageUri(Context context) { String name = "boreWbImg" + System.currentTimeMillis(); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, name); values.put(MediaStore.Images.Media.DISPLAY_NAME, name + ".jpeg"); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); Uri uri = context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); return uri;/*w ww .ja v a 2s . com*/ }
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. * //w ww . j a v a 2 s.c om * @param context * The context. * @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 = MediaColumns.DATA; final String[] projection = { column }; try { cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:Main.java
private static long fileUriFileSize(Context context, String contentUri) { long result = 0; String[] p = { MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.SIZE }; Uri uri = Uri.parse(contentUri);//from ww w.java 2 s . c o m String path = uri.getPath(); String last = Uri.parse(path).getLastPathSegment(); Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, p, // which columns MediaStore.MediaColumns.DISPLAY_NAME + "='" + last + "'", // which rows null, // selection args (none) null); // order-by clause (ascending by name) if (cursor != null) { int scol = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE); if (cursor.moveToFirst()) { result = cursor.getLong(scol); } } return (result); }
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.// ww w .jav a 2s .c o m * @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:com.diona.videoplugin.CameraUtil.java
/** * Gets a byte array from an Intent.//from w w w . j av a2s .c o m * * @param context * used to access the file system. * @param data * the Intent that holds the data. * @return the data in the Intent converted to a byte[]. */ public static byte[] getByteArray(final Context context, final Intent data) { byte[] videoBytes = null; try { final InputStream iStream = context.getContentResolver() .openInputStream(FileCacheUtil.getOutputMediaFileUriForVideos()); videoBytes = IOUtils.toByteArray(iStream); iStream.close(); } catch (final IOException e) { LogUtil.error(TAG, e); return null; } return videoBytes; }