List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
public static String getNewThreadID(Context context) { int new_id = 0; final String[] projection = new String[] { "_id" }; Uri uri = Uri.parse("content://mms-sms/conversations?simple=true"); Cursor query = context.getContentResolver().query(uri, projection, null, null, "date DESC"); if (query != null) { while (query.moveToNext()) { int tmp = query.getInt(query.getColumnIndexOrThrow("_id")) + 1; if (tmp > new_id) { new_id = tmp; }//w w w. j a v a 2 s .co m } query.close(); } return "" + new_id; }
From source file:Main.java
private static boolean isMobileDataEnabledFromSettings(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { // The row has been moved to 'global' table in API level 17 return Settings.Global.getInt(context.getContentResolver(), "mobile_data", 0) != 0; }//www.j ava2 s.c o m try { // It was in 'secure' table before return Settings.Secure.getInt(context.getContentResolver(), "mobile_data") != 0; } catch (Settings.SettingNotFoundException e) { // It was in 'system' table originally, but I don't remember when that was the case. // So, probably, you won't need all these try/catches. // But, hey, it is better to be safe than sorry :) return Settings.System.getInt(context.getContentResolver(), "mobile_data", 0) != 0; } }
From source file:Main.java
/** * Copy uri to Clipboard/* www. j ava 2 s. c o m*/ * * @param context * @param uri */ public static void copy(Context context, Uri uri) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newUri(context.getContentResolver(), null, uri)); }
From source file:Main.java
public static String getPersonNameFromNumber(Context context, String box, String address) { if (address == null) { return "unknown"; }// ww w . ja v a 2 s . c o m if (!box.equalsIgnoreCase("draft")) { Cursor cursor = context.getContentResolver().query( Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address)), new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); if (cursor != null) { try { if (cursor.getCount() > 0) { cursor.moveToFirst(); String name = cursor.getString(0); return name; } } finally { cursor.close(); } } } if (address != null) { return PhoneNumberUtils.formatNumber(address); } return "unknown"; }
From source file:Main.java
/** * Calculates the amount of rotation needed for the image to look upright. * //w w w . ja v a 2 s . co m * @param context * the application's context * @param uri * the Uri pointing to the file * @return the needed rotation as a <code>float</code> */ private static float rotationForImage(Context context, Uri uri) { if ("content".equals(uri.getScheme())) { String[] projection = { Images.ImageColumns.ORIENTATION }; Cursor c = context.getContentResolver().query(uri, projection, null, null, null); if (c.moveToFirst()) { return c.getInt(0); } } else if ("file".equals(uri.getScheme())) { try { ExifInterface exif = new ExifInterface(uri.getPath()); int rotation = (int) exifOrientationToDegrees( exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)); return rotation; } catch (IOException e) { Log.e(TAG, "Error checking exif", e); } } return 0f; }
From source file:Main.java
public static Uri writeToTempImageAndGetPathUri(Context inContext, Bitmap inImage) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null); return Uri.parse(path); }
From source file:Main.java
public static final Uri getImageUri(Context inContext, Bitmap inImage) { // ByteArrayOutputStream bytes = new ByteArrayOutputStream(); // inImage.compress(Bitmap.CompressFormat.PNG, 100, bytes); String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null); return Uri.parse(path); }
From source file:Main.java
public static String getRealPathByUri(Context context, Uri uri) { if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) { return uri.getPath(); }// ww w. j a v a 2 s . co m try { ContentResolver resolver = context.getContentResolver(); String[] proj = new String[] { MediaStore.Images.Media.DATA }; Cursor cursor = MediaStore.Images.Media.query(resolver, uri, proj); String realPath = null; if (cursor != null) { int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); if (cursor.getCount() > 0 && cursor.moveToFirst()) { realPath = cursor.getString(columnIndex); } cursor.close(); } return realPath; } catch (Exception e) { return uri.getPath(); } }
From source file:Main.java
public static Uri getImageUri(Context inContext, Bitmap inImage) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "croppedImage", null);//from ww w . j a v a 2 s. c o m return Uri.parse(path); }
From source file:Main.java
/** * Get contact photo bitmap./*from ww w. j a va 2 s . c o m*/ * * @param context context. * @param photo photo uri. * @return bitmap. */ public static Bitmap getContactBitmapFromURI(Context context, String photo) { // Get photo uri. Uri uri = Uri.parse(photo); try { // Get input. InputStream input = context.getContentResolver().openInputStream(uri); if (input == null) { return null; } return getRoundedCornerBitmap(BitmapFactory.decodeStream(input)); } catch (FileNotFoundException ignored) { } return null; }