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 getOrientation(Context context, Uri photoUri) {
    /* it's on the external media. */
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

    if (cursor.getCount() != 1) {
        return -1;
    }//from   ww  w .ja v a 2s  .co m

    cursor.moveToFirst();
    return cursor.getInt(0);
}

From source file:Main.java

public static int getMaxSize(Context context) {
    // Note that this URI is safe to call on the UI thread.
    Cursor c = context.getContentResolver().query(DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI,
            new String[] { DisplayPhoto.DISPLAY_MAX_DIM }, null, null, null);
    try {// www .j av a2  s.  c o  m
        c.moveToFirst();
        return c.getInt(0);
    } finally {
        c.close();
    }
}

From source file:Main.java

public static int getSmsCount(Context context) {
    try {/*from www .  jav a 2 s  .  c  om*/
        int result = 0;
        Cursor c = context.getContentResolver().query(Uri.parse("content://sms/inbox"),
                new String[] { "count(_id)", }, null, null, null);
        if (c.moveToFirst()) {
            result = c.getInt(0);
        }
        c.close();
        return result;
    } catch (Throwable t) {
        LOGE("getSmsCount: " + t.getMessage());
        t.printStackTrace();
    }
    return 0;
}

From source file:Main.java

public static void removeAttendees(Context c, long eventID) {
    String where = Attendees.EVENT_ID + " = '" + eventID + "'";
    c.getContentResolver().delete(Attendees.CONTENT_URI, where, null);
}

From source file:Main.java

public static Uri getAudioContentUri(Context context, File file) {
    String filePath = file.getAbsolutePath();
    Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
            new String[] { MediaStore.Audio.Media._ID }, MediaStore.Audio.Media.DATA + "=?",
            new String[] { filePath }, null);
    cursor.moveToFirst();// w ww.ja  v  a  2  s.c o  m
    int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
    Uri baseUri = Uri.parse("content://media/external/audio/media");
    return Uri.withAppendedPath(baseUri, "" + id);
}

From source file:Main.java

public static String getAbsoluteImagePath(Context context, Uri uri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
    cursor.moveToFirst();//from ww w  .  j a va  2  s  . c  o  m
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    return cursor.getString(column_index);
}

From source file:Main.java

public static int getScreenMode(Context context) {
    int screenMode = 0;
    try {/*from w w w .j a  va 2s  .  c om*/
        screenMode = Settings.System.getInt(context.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE);
    } catch (Exception localException) {
        localException.printStackTrace();
    }
    return screenMode;
}

From source file:Main.java

private static int getScreenMode(Context context) {
    int screenMode = 0;
    try {/*from   www.j  a v  a 2 s  .c  o m*/
        screenMode = Settings.System.getInt(context.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE);
    } catch (Exception localException) {

    }
    return screenMode;
}

From source file:Main.java

public static boolean deleteSms(Context context, String msgId) {
    LOGI("deleteSms " + msgId);
    try {/* ww w.  ja va 2  s  .c o m*/
        context.getContentResolver().delete(Uri.parse("content://sms/" + msgId), null, null);
        return true;
    } catch (Exception e) {
        LOGE("deleteSms: " + e.getMessage());
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static String convertMediaUriToPath(Context context, Uri uri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();/*from  w  w  w.j a va  2  s.  c o m*/
    String path = cursor.getString(column_index);
    cursor.close();
    return path;
}