Example usage for android.content Context getContentResolver

List of usage examples for android.content Context getContentResolver

Introduction

In this page you can find the example usage for android.content Context getContentResolver.

Prototype

public abstract ContentResolver getContentResolver();

Source Link

Document

Return a ContentResolver instance for your application's package.

Usage

From source file:Main.java

public static int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath) {
    int rotate = 0;
    try {//from w  w w.j  ava2  s.co m
        context.getContentResolver().notifyChange(imageUri, null);
        File imageFile = new File(imagePath);

        ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
        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

public static String getRealPathFromURI(Context context, long album_id) {
    Cursor cursor = null;/*from  www  . j ava 2 s.c  om*/
    try {
        cursor = context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
                new String[] { MediaStore.Audio.Albums.ALBUM_ART }, MediaStore.Audio.Albums._ID + "=?",
                new String[] { String.valueOf(album_id) }, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM_ART);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:Main.java

public static Bitmap getThumbnail(Uri uri, Context context) throws FileNotFoundException, IOException {
    InputStream input = context.getContentResolver().openInputStream(uri);

    BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options();
    onlyBoundsOptions.inJustDecodeBounds = true;
    onlyBoundsOptions.inDither = true;//optional
    onlyBoundsOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional
    BitmapFactory.decodeStream(input, null, onlyBoundsOptions);
    input.close();//from w w  w.  j av  a  2s  .  c om
    if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1))
        return null;

    int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight
            : onlyBoundsOptions.outWidth;

    double ratio = (originalSize > THUMBNAIL_SIZE) ? (originalSize / THUMBNAIL_SIZE) : 1.0;

    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
    bitmapOptions.inSampleSize = getPowerOfTwoForSampleRatio(ratio);
    bitmapOptions.inDither = true;//optional
    bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional
    input = context.getContentResolver().openInputStream(uri);
    Bitmap bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions);
    input.close();
    return bitmap;
}

From source file:Main.java

public static int getRotationFromUri(Context context, Uri imageUri) {
    String[] orientationColumn = { MediaStore.Images.Media.ORIENTATION };
    Cursor cur = context.getContentResolver().query(imageUri, orientationColumn, null, null, null);
    int orientation = -1;
    if (cur != null && cur.moveToFirst()) {
        orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
    }// ww  w .  ja v  a2  s .  c  o  m

    return orientation;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static int getAirplaneModeState(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);
    } else {/*from   w  ww. j a v a 2s.  c o  m*/
        return Settings.Global.getInt(context.getContentResolver(), Settings.Global.AIRPLANE_MODE_ON, 0);
    }
}

From source file:Main.java

public static float getScreenBrightness(Context mContext) {
    int screenBrightness = 255;
    try {//from  ww w  .  ja va 2 s  .  co m
        screenBrightness = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return screenBrightness / 255.0F * 100;
}

From source file:Main.java

/**
 * Gets an unique device Id depending on the sdk version
 *
 * @param context/*from  w  ww . ja va2 s .c  o m*/
 * @return
 */
public static String getUniqueDeviceId(Context context) {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
        return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    } else {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getDeviceId();
    }
}

From source file:Main.java

public static String get(Context context, String key) {
    String temp = null;//from  w  w w .ja v a 2 s . c  om
    Cursor cur = null;
    try {
        cur = context.getContentResolver().query(CONTENT_URI, null, "key='" + key + "'", null, null);
        if (null != cur && cur.moveToFirst())
            temp = cur.getString(1);

    } catch (Exception e) {
        Log.e("AspShareUtil", "Error while get", e);
    } finally {
        if (cur != null)
            cur.close();
    }
    return temp;
}

From source file:de.uniluebeck.itm.coapserver.Utils.java

/**
 * Returns a unique device id, which is stable across restarts
 * @param context/*from   w w  w  .j av  a 2  s.  co  m*/
 * @return
 */
public static String deviceId(Context context) {
    return Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
}

From source file:Main.java

static InputStream openContentInputStream(Context context, Uri uri) {
    try {// w  w  w.j  a v a 2 s. com
        return context.getContentResolver().openInputStream(uri);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}