List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
/** Returns a BitmapFactory.Options object containing the size of the image at the given URI, * without actually loading the image./*from w ww. j a v a 2s. com*/ */ public static BitmapFactory.Options computeBitmapSizeFromURI(Context context, Uri imageURI) throws FileNotFoundException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(context.getContentResolver().openInputStream(imageURI), null, options); return options; }
From source file:Main.java
public static void openCamera(Context context, int code) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues())); // intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory() + imagePath))); ((Activity) context).startActivityForResult(intent, code); } else//w ww . j ava 2s. c o m Toast.makeText(context, "no sdcard!", Toast.LENGTH_SHORT).show(); }
From source file:com.outsystemscloud.andrevieira.secureDevice.java
/** * @param context// w w w .ja v a 2s. c om * @return true if pattern set, false if not (or if an issue when checking) */ private static boolean isPatternSet(Context context) { ContentResolver cr = context.getContentResolver(); try { // This constant was deprecated in API level 23. // Use KeyguardManager to determine the state and security level of the keyguard. // Accessing this setting from an app that is targeting M or later throws a SecurityException. if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) { int lockPatternEnable = Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED); return lockPatternEnable == 1; } else { return false; } } catch (Settings.SettingNotFoundException e) { return false; } }
From source file:Main.java
public static boolean isInputMethodDefault(Context context, Class<?> imeClass) { final String targetImePackage = imeClass.getPackage().getName(); final String targetImeClass = imeClass.getSimpleName(); final String defaultImeId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); return defaultImeId != null && defaultImeId.contains(targetImePackage) && defaultImeId.contains(targetImeClass); }
From source file:Main.java
@Nullable public static Cursor query(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, int limit) { try {/* ww w.j a v a 2 s . co m*/ ContentResolver resolver = context.getContentResolver(); if (resolver == null) { return null; } if (limit > 0) { uri = uri.buildUpon().appendQueryParameter("limit", "" + limit).build(); } return resolver.query(uri, projection, selection, selectionArgs, sortOrder); } catch (UnsupportedOperationException ex) { return null; } }
From source file:Main.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null;/* ww w .ja va2s . co m*/ 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); } } catch (Exception e) { Log.d("android_utilities", "the error is " + e); } finally { if (cursor != null) { cursor.close(); } } return null; }
From source file:Main.java
public static boolean isInputMethodEnabled(Context context, Class<?> imeClass) { final String targetImePackage = imeClass.getPackage().getName(); final String targetImeClass = imeClass.getSimpleName(); final String enabledImeIds = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_INPUT_METHODS); return enabledImeIds != null && enabledImeIds.contains(targetImePackage) && enabledImeIds.contains(targetImeClass); }
From source file:Main.java
public static Drawable load_drawable_from_uri_string(Context context, String uri, int sizeX, int sizeY) { Drawable drawable = null;/*from www . j av a2 s .co m*/ Uri img_uri = Uri.parse(uri); if (uri != null) { try { InputStream inputStream = context.getContentResolver().openInputStream(img_uri); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); Bitmap small_bitmap = Bitmap.createScaledBitmap(bitmap, sizeX, sizeY, false); bitmap.recycle(); drawable = new BitmapDrawable(context.getResources(), small_bitmap); } catch (FileNotFoundException e) { e.printStackTrace(); } } return drawable; }
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 w ww . j a v a 2 s . com*/ * @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 index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:Main.java
public static String queryAudioName(Context context, Uri name) { String audioId;/* w ww .j a v a 2 s . c o m*/ String uriName = name.toString(); uriName = uriName.substring(uriName.lastIndexOf("/") + 1); Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); int counter = cursor.getCount(); for (int j = 0; j < counter; j++) { audioId = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media._ID)); if (uriName.equals(audioId)) { uriName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); } else { Ringtone ringtone = RingtoneManager.getRingtone(context, name); uriName = ringtone.getTitle(context); break; } cursor.moveToNext(); } cursor.close(); } else { try { Ringtone ringtone = RingtoneManager.getRingtone(context, name); uriName = ringtone.getTitle(context); } catch (Exception e) { return uriName; } } return uriName; }