List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
public static int getLastImageId(Context context) { final String[] imageColumns = { Images.Media._ID }; final String imageOrderBy = Images.Media._ID + " DESC"; Cursor cursor = context.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, imageColumns, null, null, imageOrderBy);//from ww w . j a va 2s . co m if (cursor == null) return 0; int id = 0; if (cursor.moveToFirst()) { id = cursor.getInt(cursor.getColumnIndex(Images.Media._ID)); } cursor.close(); return id; }
From source file:altermarkive.uploader.Report.java
public static String id(Context context) { return Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); }
From source file:Main.java
public static Matrix rotateImage(Context context, Uri imageUri, File f) { Matrix matrix = new Matrix(); try {//from w w w. j a va2 s.com if (imageUri != null) { context.getContentResolver().notifyChange(imageUri, null); } ExifInterface exif = new ExifInterface(f.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: matrix.postRotate(270); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.postRotate(180); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.postRotate(90); break; } } catch (Exception e) { e.printStackTrace(); } return matrix; }
From source file:Main.java
private static byte[] getBytesFromDriveVideoUri(Context context, Uri uri) { InputStream inputStream = null; try {/*from w w w . j a va 2 s . c o m*/ inputStream = context.getContentResolver().openInputStream(uri); } catch (FileNotFoundException e) { e.printStackTrace(); } if (inputStream == null) { return null; } int maxBufferSize = 1024 * 1024; int available = 0; try { available = inputStream.available(); } catch (IOException e) { e.printStackTrace(); } if (available == 0) { available = maxBufferSize; } int bufferSize = Math.min(available, maxBufferSize); byte[] data = new byte[bufferSize]; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; try { while ((nRead = inputStream.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } } catch (IOException e) { e.printStackTrace(); } try { buffer.flush(); } catch (IOException e) { e.printStackTrace(); } return buffer.toByteArray(); }
From source file:Main.java
/** * @param context The {@link Context} to use. * @param name The name of the new playlist. * @return A new playlist ID./*ww w .ja v a 2s . c o m*/ */ public static final long createPlaylist(final Context context, final String name) { if (name != null && name.length() > 0) { final ContentResolver resolver = context.getContentResolver(); final String[] projection = new String[] { PlaylistsColumns.NAME }; final String selection = PlaylistsColumns.NAME + " = '" + name + "'"; Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, selection, null, null); if (cursor.getCount() <= 0) { final ContentValues values = new ContentValues(1); values.put(PlaylistsColumns.NAME, name); final Uri uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values); return Long.parseLong(uri.getLastPathSegment()); } if (cursor != null) { cursor.close(); cursor = null; } return -1; } return -1; }
From source file:Main.java
public static final boolean checkImageAndSize(Context context, Uri uri, long bytes) { if (uri == null) return false; try {/*from w w w . ja v a 2 s .c o m*/ InputStream is = context.getContentResolver().openInputStream(uri); BitmapFactory.Options imageOptions = new BitmapFactory.Options(); imageOptions.inJustDecodeBounds = true; BitmapFactory.decodeStream(is, null, imageOptions); //android.util.Log.d("test77", "Original Image Size: " + imageOptions.outWidth + " x " + imageOptions.outHeight); is.close(); if (imageOptions.outWidth <= 0 || imageOptions.outHeight <= 0) { return false; } is = context.getContentResolver().openInputStream(uri); long fileSizeCounter = 0; long size; byte[] buf = new byte[8192]; while ((size = is.read(buf, 0, buf.length)) != -1) { //android.util.Log.d("test77", "size="+size); fileSizeCounter += size; } is.close(); if (fileSizeCounter > bytes) { return false; } return true; } catch (Exception ex) { ex.printStackTrace(); return false; } }
From source file:Main.java
public static int getOrientation(Context context, Uri photoUri, File file) { /* it's on the external media. */ Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor != null && cursor.getCount() != 1) { cursor.moveToFirst();/*from w w w . j a v a 2 s.c om*/ return cursor.getInt(0); } int rotate = 0; ExifInterface exif = null; try { exif = new ExifInterface(file == null ? getPath(context, photoUri) : file.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } 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; case ExifInterface.ORIENTATION_NORMAL: rotate = 0; break; } return rotate; }
From source file:com.frostwire.android.MediaScanner.java
private static long getSize(Context context, Uri uri) { Cursor c = null;//from w w w. j av a 2 s . co m try { c = context.getContentResolver().query(uri, new String[] { "_size" }, null, null, null); if (c != null && c.moveToFirst()) { return c.getLong(0); } } catch (Throwable e) { LOG.error("Error getting file size for uri: " + uri, e); } finally { IOUtils.closeQuietly(c); } return 0; }
From source file:Main.java
public static byte[] getPersonPhoto(Context context, String id) { if (id == null) return null; byte photo[] = null; Cursor cursor = context.getContentResolver().query(Uri.withAppendedPath(Contacts.Photos.CONTENT_URI, id), new String[] { PhotosColumns.DATA }, null, null, null); if (cursor != null) { try {/* www. ja va 2 s . c om*/ if (cursor.getCount() > 0) { cursor.moveToFirst(); photo = cursor.getBlob(0); if (photo != null) { return photo; // Log.v("Found photo for person: " + id); // bitmap = BitmapFactory.decodeStream(new // ByteArrayInputStream(photo)); } } } finally { cursor.close(); } } return photo; }
From source file:Main.java
public static boolean hasPermission(Context context, String permissionType) { Uri uri = Uri.parse("content://com.google.atap.tango.PermissionStatusProvider/" + permissionType); Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); if (cursor == null) { return false; } else {/*from w w w . ja va 2s .c o m*/ return true; } }