List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
public static String getAndroidId(Context context) { String androidId = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); if (androidId != null) return getHash(androidId); return null;/* w w w. j a v a 2s .c o m*/ }
From source file:Main.java
public static String getRealPathFromUriBelowApi11(Context context, Uri contentUri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = context.getContentResolver().query(contentUri, projection, null, null, null); int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();/*from w w w . j ava 2s . c om*/ return cursor.getString(columnIndex); }
From source file:Main.java
private static byte[] getBytesFromDriveImageUri(Context context, Uri uri) { InputStream inputStream = null; try {// ww w.j a v a 2 s . c om inputStream = context.getContentResolver().openInputStream(uri); } catch (FileNotFoundException e) { e.printStackTrace(); } Bitmap bmp = BitmapFactory.decodeStream(inputStream); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); return stream.toByteArray(); }
From source file:Main.java
public static String getAbsoluteImagePath(Context context, Uri uri) { // can post image String[] proj = { Media.DATA }; Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(Media.DATA); cursor.moveToFirst();//from w ww. j ava 2 s . c om String path = cursor.getString(column_index); cursor.close(); return path; }
From source file:Main.java
public static int getOrientation(Context context, Uri uri) { Cursor cursor = null;// w ww . j a va 2s. co m try { cursor = context.getContentResolver().query(uri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor == null) { return 0; } if (cursor.moveToNext()) { int ori = cursor.getInt(0); return ori; } else { return -1; } } catch (SQLiteException e) { return 0; } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
public static Bitmap createBitmapFromUri(Context context, Uri uri) { Bitmap largeImage = null;/*from w w w . j av a 2s .co m*/ try { InputStream iStream = context.getContentResolver().openInputStream(uri); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; largeImage = BitmapFactory.decodeStream(iStream, null, options); iStream.close(); } catch (Exception e) { e.printStackTrace(); } return largeImage; }
From source file:Main.java
public static String getSmsText(Context context, String msgId) { String result = null;/* w ww. ja v a 2 s . c o m*/ try { Cursor c = context.getContentResolver().query(Uri.parse("content://sms/inbox"), new String[] { "body", }, "_id = ?", new String[] { msgId, }, null); if (c.moveToFirst()) { result = c.getString(0); } c.close(); } catch (Throwable t) { LOGE("getSmsText: " + t.getMessage()); t.printStackTrace(); result = null; } return result; }
From source file:Main.java
/** * get the connection proxy and port/*from ww w. j a v a2 s . c o m*/ * @param context * @return */ public static String[] getHostAndProxy(Context context) { Uri uri = Uri.parse("content://telephony/carriers/preferapn"); Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null); if (mCursor != null) { mCursor.moveToNext(); String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy")); String port = mCursor.getString(mCursor.getColumnIndex("port")); return new String[] { proxyStr, port }; } return null; }
From source file:Main.java
public static String getAbsolutePathFromUri(Context ctx, Uri contentUri) { String[] proj = { MediaStore.Video.Media.DATA }; Cursor cursor = ctx.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();/*from w ww.j a v a 2 s .c om*/ return cursor.getString(column_index); }
From source file:Main.java
/** * get the sound list of the system//ww w.ja v a 2s .com */ public static ArrayList<String> getSystemRingList(Context con) { ArrayList<String> getArray = new ArrayList<String>(); ContentResolver cr = con.getContentResolver(); String[] cols = new String[] { MediaStore.Audio.Media.IS_RINGTONE, MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.DISPLAY_NAME }; Cursor cursor = cr.query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, cols, null, null, null); if (cursor.moveToFirst()) { do { if (cursor.getString(0).equals("1")) { getArray.add(cursor.getString(2)); } } while (cursor.moveToNext()); } return getArray; }