List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
public static int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath) { int rotate = 0; try {//from w w w.j av a2 s. c o m context.getContentResolver().notifyChange(imageUri, null); File imageFile = new File(imagePath); ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; } } catch (Exception e) { e.printStackTrace(); } return rotate; }
From source file:Main.java
public static Bitmap getVedioThubnailPath(String id, Context context) { long vedioId = Long.valueOf(id); BitmapFactory.Options option = new BitmapFactory.Options(); return Thumbnails.getThumbnail(context.getContentResolver(), vedioId, Thumbnails.MINI_KIND, option); }
From source file:Main.java
/** * Generate an input stream reading from an android URI * //from ww w.j av a 2 s .co m * @param uri * @return * @throws IOException */ public static InputStream getFromURI(Context context, Uri uri) throws IOException { if (uri.getScheme().equals("content")) return context.getContentResolver().openInputStream(uri); else if (uri.getScheme().equals("file")) { URL url = new URL(uri.toString()); return url.openStream(); } else { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(uri.toString()); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) return entity.getContent(); else throw new IOException("No HTTP response"); // Use the regular java stuff // URL url = new URL(uri.toString()); // return url.openStream(); } }
From source file:Main.java
public static Bitmap getImageFromUri(Context ctx, Uri uri, int reqWidth, int reqHeight) throws IOException { InputStream iStream = ctx.getContentResolver().openInputStream(uri); byte[] inputData = getBytes(iStream); return decodeSampledBitmapFromBytes(inputData, reqWidth, reqHeight); }
From source file:Main.java
public static Uri bitmap2Uri(final Context context, final Bitmap bitmap) { return context == null || bitmap == null ? null : Uri.parse(MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, null, null)); }
From source file:Main.java
public static final Bitmap getBitmapFromUri(Context context, Uri uri) { if (uri == null) return null; try {// w w w.ja v a 2 s. co m InputStream is = context.getContentResolver().openInputStream(uri); BitmapFactory.Options imageOptions = new BitmapFactory.Options(); Bitmap bmp = BitmapFactory.decodeStream(is, null, imageOptions); return bmp; } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:Main.java
public static String formatTimestamp(Context context, long timestamp) { String HOURS_24 = "24"; String hours;//from w ww . ja v a 2s . c o m hours = Settings.System.getString(context.getContentResolver(), Settings.System.TIME_12_24); SimpleDateFormat mSDF = new SimpleDateFormat(); if (HOURS_24.equals(hours)) { mSDF.applyLocalizedPattern(TIME_FORMAT_24_HOUR); } else { mSDF.applyLocalizedPattern(TIME_FORMAT_12_HOUR); } return mSDF.format(new Date(timestamp)); }
From source file:Main.java
/** * @param context The {@link Context} to use. * @param playlistId The playlist ID.//from ww w .j av a2s . co m */ public static void clearPlaylist(final Context context, final int playlistId) { final Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId); context.getContentResolver().delete(uri, null, null); return; }
From source file:Main.java
public static Bitmap getBitmapFromUri(Uri uri, Context context) { ParcelFileDescriptor parcelFileDescriptor = null; try {/*from w ww. jav a2 s. c o m*/ parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r"); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor); parcelFileDescriptor.close(); return image; } catch (Exception e) { Log.e(TAG, "Failed to load image.", e); return null; } finally { try { if (parcelFileDescriptor != null) { parcelFileDescriptor.close(); } } catch (IOException e) { e.printStackTrace(); Log.e(TAG, "Error closing ParcelFile Descriptor"); } } }
From source file:Main.java
public static Bitmap getThumbnail(Context context, Uri uri, int size) throws FileNotFoundException, IOException { InputStream input = context.getContentResolver().openInputStream(uri); BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options(); onlyBoundsOptions.inJustDecodeBounds = true; onlyBoundsOptions.inDither = true;//optional onlyBoundsOptions.inPreferredConfig = Config.ARGB_8888;//optional BitmapFactory.decodeStream(input, null, onlyBoundsOptions); input.close();/* ww w. java 2s . co m*/ if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1)) return null; int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight : onlyBoundsOptions.outWidth; double ratio = (originalSize > size) ? (originalSize / size) : 1.0; BitmapFactory.Options bitmapOptions = new BitmapFactory.Options(); bitmapOptions.inSampleSize = getPowerOfTwoForSampleRatio(ratio); bitmapOptions.inDither = true;//optional bitmapOptions.inPreferredConfig = Config.ARGB_8888;//optional input = context.getContentResolver().openInputStream(uri); Bitmap bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions); input.close(); return bitmap; }