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 getScreenMode(Context mContext) {
    int screenMode = 0;
    try {/*from w w w.j av a 2  s  .  c  om*/
        screenMode = Settings.System.getInt(mContext.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE);
    } catch (Exception localException) {

    }
    return screenMode;
}

From source file:Main.java

public static String getRealPathFromURI_BelowAPI11(Context context, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();//from www  . ja  v a2  s  .c o m
    return cursor.getString(column_index);
}

From source file:Main.java

/**
 * Generates client ID for Android device.
 * @param context used to generate hostname.
 * @return hostname.//from ww w  . j a  v a 2 s . com
 */
public static String getClientId(Context context) {
    return Build.MODEL.replaceAll(" ", "-") + "-"
            + Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}

From source file:Main.java

public static String getUriFromBitmap(Context context, Bitmap bitmap, String title, String description) {
    String sUrl = MediaStore.Images.Media.insertImage(context.getContentResolver(), bitmap, title, description);
    return sUrl;/*from   w  ww.j a va  2  s .  c om*/
}

From source file:Main.java

/**
 * Return a {@link BufferedInputStream} from the given uri or null if an
 * exception is thrown/*from   w w w.j a v  a2s.  c o m*/
 *
 * @param context
 * @param uri
 * @return the {@link InputStream} of the given path. null if file is not
 *         found
 */
static InputStream openContentInputStream(Context context, Uri uri) {
    try {
        return context.getContentResolver().openInputStream(uri);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

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

From source file:Main.java

public static String getAccountType(Context context, long id, String name) {
    try {//from w  w  w .  jav  a2  s.  c o m
        Cursor cur = context.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI,
                new String[] { ContactsContract.RawContacts.ACCOUNT_TYPE,
                        ContactsContract.RawContacts.ACCOUNT_NAME },
                ContactsContract.RawContacts.CONTACT_ID + " = ?", new String[] { String.valueOf(id) }, null);
        if (cur != null) {
            String str = "";
            while (cur.moveToNext()) {
                str += cur.getString(cur.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE));
            }
            //                Log.v("getAccountType", name+" => "+str);
            cur.close();
            Matcher m = accountTypePattern.matcher(str);
            String last = "";
            while (m.find()) {
                last = m.group(1);
            }
            return last;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static int getScreenBrightness(Context context) {
    int rightnessValue = 0;
    try {/*from   w  w w .  jav a 2  s.c o  m*/
        rightnessValue = Settings.System.getInt(context.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS);
    } catch (SettingNotFoundException e) {
        e.printStackTrace();
    }
    return rightnessValue;
}

From source file:Main.java

public static String getAndroidID(Context context) {

    if (context == null)
        return "";
    String device_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
    return device_id;
}

From source file:Main.java

public static String query(Context context, Uri uri) {
    if (context == null || uri == null)
        return "";
    Cursor cursor = context.getContentResolver().query(uri,
            new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null);
    cursor.moveToNext();/*w ww.  j av a  2 s. co  m*/
    return cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
}