List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
/** * Decodifica ottimizzata per la memoria dei bitmap * //from w ww. j a va 2s .com * @param uri * URI bitmap * @param reqWidth * Larghezza richiesta * @param reqHeight * Altezza richiesta * @return * @throws FileNotFoundException */ public static Bitmap decodeSampledFromUri(Context mContext, Uri uri, int reqWidth, int reqHeight) throws FileNotFoundException { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(mContext.getContentResolver().openInputStream(uri), null, options); // Setting decode options options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inJustDecodeBounds = false; // Bitmap is now decoded for real using calculated inSampleSize Bitmap bmp = BitmapFactory.decodeStream(mContext.getContentResolver().openInputStream(uri), null, options); return bmp; }
From source file:Main.java
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null;/*from www.j av a 2 s. co m*/ 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); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:Main.java
/** * get app imei/* w w w. j a v a 2s . c o m*/ * @param context * @return */ @TargetApi(Build.VERSION_CODES.CUPCAKE) public static String getDeviceIMEI(Context context) { String deviceId; if (isPhone(context)) { TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); deviceId = telephony.getDeviceId(); } else { deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); } return deviceId; }
From source file:Main.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null;// w ww . j ava 2 s . com 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); } } finally { if (cursor != null) cursor.close(); } return null; }
From source file:Main.java
/** * Looks up contact name in the address book by the phone number. * //from ww w .j a v a 2 s. c o m * @param context the Android context. * @param phone the phone number to look up. * @return a contact name. */ public static String lookupNameByPhone(Context context, String phone) { Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone)); String[] projection = new String[] { ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts._ID }; Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); try { while (cursor.moveToNext()) { String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); if (name != null && name.length() > 0) { return name; } } } finally { cursor.close(); } return phone; }
From source file:Main.java
public static String uriToString(Context context, Uri uri) { String scheme = uri.getScheme(); if (scheme != null) { if (scheme.equals("http") || scheme.equals("https")) { return uri.toString(); } else if (scheme.equals("content") || scheme.equals("file")) { Cursor cursor = context.getContentResolver().query(uri, new String[] { OpenableColumns.DISPLAY_NAME }, null, null, null); if (cursor.moveToNext()) { String name = cursor.getString(0); cursor.close();/*w w w . j a v a2s.co m*/ return name; } cursor.close(); return uri.getPath(); } } return uri.toString(); }
From source file:Main.java
protected static String getImagePath(Uri imageUri, Context context) { String scheme = imageUri.getScheme(); if (scheme.equals("file")) return imageUri.getPath(); Cursor cursor = null;/*w ww . jav a2 s .c om*/ try { String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(imageUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } finally { if (cursor != null) cursor.close(); } }
From source file:Main.java
private static String generateDeviceUniqueIdentifier(Context context) { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); final String tmDevice = "" + tm.getDeviceId(); final String tmSerial = "" + tm.getSimSerialNumber(); final String androidId = "" + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); final String packageBasedAndroidId = context.getPackageName() + androidId; UUID deviceUuid = new UUID(packageBasedAndroidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); return deviceUuid.toString(); }
From source file:Main.java
public static String getDeviceKey(Context ctx) { final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE); final String tmDevice, tmSerial, androidId; tmDevice = "" + tm.getDeviceId(); tmSerial = "" + tm.getSimSerialNumber(); androidId = "" + android.provider.Settings.Secure.getString(ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode()); return deviceUuid.toString(); }
From source file:Main.java
public static String getMacAddress(Context context) { WifiManager wimanager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); String macAddress = wimanager.getConnectionInfo().getMacAddress(); if (macAddress == null) { //Device doesn't have mac address or wi-fi is disabled macAddress = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); }// w w w . j ava 2 s . co m return macAddress; }