List of usage examples for android.content Context getContentResolver
public abstract ContentResolver getContentResolver();
From source file:Main.java
public static String getApplicationUserName(Context context, String s) { return (new StringBuilder()).append(s).append("_") .append(android.provider.Settings.Secure.getString(context.getContentResolver(), "android_id")) .toString();//from w w w .java 2s .c o m }
From source file:Main.java
public static boolean checkLocationSystemSetting(Context context) { int locationSettingState = 0; try {//from w w w. j a v a 2 s . co m locationSettingState = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); } catch (Settings.SettingNotFoundException e) { e.printStackTrace(); } return locationSettingState != Settings.Secure.LOCATION_MODE_OFF; }
From source file:Main.java
private static int getRotationFromCamera(Context context, Uri imageFile) { int rotate = 0; try {//from w w w.j a v a 2 s . c om context.getContentResolver().notifyChange(imageFile, null); ExifInterface exif = new ExifInterface(imageFile.getPath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; } } catch (Exception e) { e.printStackTrace(); } return rotate; }
From source file:Main.java
/** * Convert an image to a byte array/* w w w.j a v a2 s .c o m*/ * @param uri * @param context * @return */ public static byte[] convertImageToByte(Uri uri, Context context) { byte[] data = null; try { ContentResolver cr = context.getContentResolver(); InputStream inputStream = cr.openInputStream(uri); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); data = baos.toByteArray(); if (inputStream != null) { try { inputStream.close(); } catch (Exception e2) { } } if (baos != null) { try { baos.close(); } catch (Exception e2) { } } } catch (FileNotFoundException e) { e.printStackTrace(); } return data; }
From source file:Main.java
public static String getAndroidID(Context applicationCtx) { if (sAndroidID != null) { return sAndroidID; }//w w w . j a va 2 s. c om sAndroidID = Settings.System.getString(applicationCtx.getContentResolver(), Settings.System.ANDROID_ID); return sAndroidID; }
From source file:Main.java
public static boolean checkShortCut(Context context, String appName) { boolean hasShortCut = false; try {/*from www . j ava 2 s. co m*/ ContentResolver cr = context.getContentResolver(); final String AUTHORITY1 = "com.android.launcher.settings"; final String AUTHORITY2 = "com.android.launcher2.settings"; String contentUri = ""; if (android.os.Build.VERSION.SDK_INT < 8) { contentUri = "content://" + AUTHORITY1 + "/favorites?notify=true"; } else { contentUri = "content://" + AUTHORITY2 + "/favorites?notify=true"; } final Uri CONTENT_URI = Uri.parse(contentUri); Cursor c = cr.query(CONTENT_URI, new String[] { "title", "iconResource" }, "title=?", new String[] { appName }, null); if (c != null && c.getCount() > 0) { hasShortCut = true; } } catch (Exception e) { } return hasShortCut; }
From source file:Main.java
public static void addCallLog(Context context, ContentValues values, ContentValues extraValues) { ContentResolver contentResolver = context.getContentResolver(); Uri result = contentResolver.insert(CallLog.Calls.CONTENT_URI, values); if (result != null) { // Announce that to other apps final Intent broadcast = new Intent(ACTION_ANNOUNCE_SIP_CALLLOG); broadcast.putExtra(EXTRA_CALL_LOG_URI, result.toString()); String provider = extraValues.getAsString(EXTRA_SIP_PROVIDER); if (provider != null) { broadcast.putExtra(EXTRA_SIP_PROVIDER, provider); }/*from ww w . j a va 2 s .com*/ context.sendBroadcast(broadcast); } }
From source file:Main.java
public final static String getUUid(Context applicationCtx) { if (sAndroidID != null) { return sAndroidID; }/*from ww w. ja v a 2 s . com*/ sAndroidID = Settings.System.getString(applicationCtx.getContentResolver(), Settings.System.ANDROID_ID); return sAndroidID; }
From source file:Main.java
/** * Get video's duration from {@link ContentProvider} * * @param context/* w w w .j a v a2 s. com*/ * @param uri must has {@link Uri#getScheme()} equals * {@link ContentResolver#SCHEME_CONTENT} * @return Duration of video, in milliseconds. */ public static long getDuration(Context context, Uri uri) { long duration = 0L; Cursor cursor = MediaStore.Video.query(context.getContentResolver(), uri, new String[] { MediaStore.Video.VideoColumns.DURATION }); if (cursor != null) { cursor.moveToFirst(); duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.VideoColumns.DURATION)); cursor.close(); } return duration; }
From source file:Main.java
/** * Decode a file from the path and return a bitmap * @param uri// w ww .j a va 2s . c o m * @param context * @return */ public static Bitmap decodeFileFromPath(Uri uri, Context context) { InputStream in = null; try { in = context.getContentResolver().openInputStream(uri); //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeStream(in, null, o); in.close(); int scale = 1; int inSampleSize = 1024; if (o.outHeight > inSampleSize || o.outWidth > inSampleSize) { scale = (int) Math.pow(2, (int) Math.round( Math.log(inSampleSize / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5))); } BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; in = context.getContentResolver().openInputStream(uri); Bitmap b = BitmapFactory.decodeStream(in, null, o2); in.close(); return b; } catch (FileNotFoundException e) { //e.printStackTrace(); } catch (IOException e) { //e.printStackTrace(); } return null; }