List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
public static Bitmap bitmapFromUri(Context context, Uri photoUri) throws FileNotFoundException, IOException { InputStream is = context.getContentResolver().openInputStream(photoUri); BitmapFactory.Options dbo = new BitmapFactory.Options(); dbo.inJustDecodeBounds = true;/*from w w w . j a va 2 s. co m*/ BitmapFactory.decodeStream(is, null, dbo); is.close(); int rotatedWidth, rotatedHeight; int orientation = 0; if (photoUri.toString().contains("content:/")) { orientation = getOrientation(context, photoUri); Log.i("Photo Editor", "Orientation: " + orientation); } else { int orientationFormExif = getOrientationFromExif(photoUri, context); orientation = decodeExifOrientation(orientationFormExif); Log.i("Photo Editor", "Orientation form Exif: " + orientation); } if (orientation == 90 || orientation == 270) { rotatedWidth = dbo.outHeight; rotatedHeight = dbo.outWidth; } else { rotatedWidth = dbo.outWidth; rotatedHeight = dbo.outHeight; } Bitmap srcBitmap = readScaledBitmapFromUri(photoUri, context, rotatedWidth, rotatedHeight); srcBitmap = setProperOrientation(orientation, srcBitmap); return srcBitmap; }
From source file:Main.java
public static void setAutoAdjustBrightness(Context context, boolean auto) { int value = 0; if (auto) {// w w w. j a v a 2 s .c o m value = Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC; } else { value = Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL; } ContentResolver cr = context.getContentResolver(); Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS_MODE, value); }
From source file:Main.java
private static boolean modifyPermission(Context context, int flag) { String packageName = context.getPackageName(); try {/*from w w w.jav a2s. co m*/ ContentValues contentValues = new ContentValues(); contentValues.put("userAccept", Integer.valueOf(flag)); context.getContentResolver().update(Uri.parse("content://com.lbe.security.miui.permmgr/active"), contentValues, "pkgName=?", new String[] { packageName }); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:Main.java
/** * Utils to get File path//from w ww .j a v a2s. c om * * @param uri * @return */ public static String getPath(Context context, Uri uri) { String scheme = uri.getScheme(); String s = null; if (scheme.equals("content")) { String[] projection = { MediaStore.Files.FileColumns.DATA }; Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATA); cursor.moveToFirst(); s = cursor.getString(columnIndex); } else if (scheme.equals("file")) { s = uri.getPath(); } // Log.d("ActionManager", "URI:" + uri + " - S:" + s); return s; }
From source file:at.amartinz.hardware.device.Device.java
public static String getAndroidId(@NonNull Context context) { return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); }
From source file:com.wishlist.Utility.java
public static byte[] scaleImage(Context context, Uri photoUri) throws IOException { InputStream is = context.getContentResolver().openInputStream(photoUri); BitmapFactory.Options dbo = new BitmapFactory.Options(); dbo.inJustDecodeBounds = true;//from w w w. j a v a 2 s. c om BitmapFactory.decodeStream(is, null, dbo); is.close(); int rotatedWidth, rotatedHeight; int orientation = getOrientation(context, photoUri); if (orientation == 90 || orientation == 270) { rotatedWidth = dbo.outHeight; rotatedHeight = dbo.outWidth; } else { rotatedWidth = dbo.outWidth; rotatedHeight = dbo.outHeight; } Bitmap srcBitmap; is = context.getContentResolver().openInputStream(photoUri); if (rotatedWidth > MAX_IMAGE_DIMENSION || rotatedHeight > MAX_IMAGE_DIMENSION) { float widthRatio = ((float) rotatedWidth) / ((float) MAX_IMAGE_DIMENSION); float heightRatio = ((float) rotatedHeight) / ((float) MAX_IMAGE_DIMENSION); float maxRatio = Math.max(widthRatio, heightRatio); // Create the bitmap from file BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = (int) maxRatio; srcBitmap = BitmapFactory.decodeStream(is, null, options); } else { srcBitmap = BitmapFactory.decodeStream(is); } is.close(); /* if the orientation is not 0 (or -1, which means we don't know), we * have to do a rotation. */ if (orientation > 0) { Matrix matrix = new Matrix(); matrix.postRotate(orientation); srcBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(), matrix, true); } String type = context.getContentResolver().getType(photoUri); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (type.equals("image/png")) { srcBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); } else if (type.equals("image/jpg") || type.equals("image/jpeg")) { srcBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); } byte[] bMapArray = baos.toByteArray(); baos.close(); return bMapArray; }
From source file:Main.java
public static String getDeviceIMEI(Context context) { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager == null || TextUtils.isEmpty(telephonyManager.getDeviceId())) { return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); } else {/*from ww w . java 2 s. c o m*/ return telephonyManager.getDeviceId(); } }
From source file:Main.java
public static Bitmap getThumbnail(Context context, long origId) { //BitmapFactory.Options bounds = new BitmapFactory.Options(); //bounds.inPurgeable=true; //bounds.inInputShareable=true; Bitmap bitmap = MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(), origId, MediaStore.Images.Thumbnails.MINI_KIND, /*bounds*/null); return bitmap; }
From source file:Main.java
/** * Get a uri's user-friendly display name * //from w w w. ja v a 2s .co m * @param context the application context * @param uri the uri to query * * @return a user-friendly display name */ public static String getUriDisplayName(Context context, Uri uri) { String displayName = null; String scheme = uri.getScheme(); if (scheme.startsWith("content")) { String[] proj = { OpenableColumns.DISPLAY_NAME }; Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null); if (cursor != null) { int columnIndex = cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME); cursor.moveToFirst(); displayName = cursor.getString(columnIndex); cursor.close(); } } else if (scheme.startsWith("file")) { displayName = uri.getLastPathSegment(); } return displayName; }
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./*www . java 2s.c om*/ * @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 = MediaStore.Images.Media.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); } } catch (IllegalArgumentException e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } return null; }