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

/**
 * Equipment is started for the first time the generated number
 * Are potential "9774d56d682e549c"//  ww  w  .j  a va 2s.  com
 *
 * @param context Context
 * @return Number
 */
public static String getAndroidId(Context context) {
    return android.provider.Settings.System.getString(context.getContentResolver(),
            android.provider.Settings.Secure.ANDROID_ID);
}

From source file:Main.java

public static int getSystemBrightness(Context context) {
    int result = 0;
    ContentResolver cr = context.getContentResolver();
    try {//from   ww w  .j a  v  a2 s. c  o m
        result = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS);
    } catch (SettingNotFoundException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

/**
 * get image path by uri/*from   w w w .j a  va 2s. c  o  m*/
 *
 * @param context context
 * @param uri     uri
 * @return image path
 */
public static String query(Context context, Uri uri) {
    Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null,
            null);
    cursor.moveToNext();
    String path = cursor.getString(cursor.getColumnIndex(ImageColumns.DATA));
    cursor.close();
    return path;
}

From source file:Main.java

public static Drawable getDrawableFromUri(Uri uri, Context context) throws FileNotFoundException {
    InputStream inputStream = context.getContentResolver().openInputStream(uri);
    return Drawable.createFromStream(inputStream, uri.toString());
}

From source file:Main.java

/**
 * @return the ANDROID_ID that identify the device, or the "emulator" string on the emulator.
 *///www.j a  va 2 s. co m
public static String getAndroidId(Context context) {
    String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    if (androidId == null || androidId.length() <= 0) {
        androidId = "emulator";
    }
    return androidId;
}

From source file:Main.java

public static Bitmap readBitmapFromPath(Context context, Uri path) throws Exception {
    InputStream stream = context.getContentResolver().openInputStream(path);
    Bitmap bitmap = BitmapFactory.decodeStream(stream);
    if (stream != null) {
        stream.close();// w  ww .  ja v  a2s .com
    }
    return bitmap;
}

From source file:Main.java

/**
 *
 * @param context/*w  w w.j  a v a2s.com*/
 * @return
 */
public static String whatGps(Context context) {
    String gs = android.provider.Settings.Secure.getString(context.getContentResolver(),
            android.provider.Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    return gs;
}

From source file:Main.java

/**
 * Return the MIME type from the URI//ww w  .j  ava 2 s  . com
 * @param context Context
 * @param uri URI
 * @return Return the MIME type
 */
public static String getMimetypeFromUri(Context context, Uri uri) {
    String contentType = context.getContentResolver().getType(uri);
    if (TextUtils.isEmpty(contentType)) {
        final MimeTypeMap type_map = MimeTypeMap.getSingleton();
        // Get the extension from the path
        String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
        extension = extension.toLowerCase();
        if (extension.contains(".")) {
            extension = extension.substring(extension.lastIndexOf("."));
        }
        contentType = type_map.getMimeTypeFromExtension(extension);
    }
    return contentType;
}

From source file:Main.java

public static String getAndroidId(Context context) {
    String androidId = android.provider.Settings.System.getString(context.getContentResolver(),
            android.provider.Settings.System.ANDROID_ID);
    return androidId;
}

From source file:Main.java

public static String getDeviceId(Context context) {
    String android_id = android.provider.Settings.Secure.getString(context.getContentResolver(),
            android.provider.Settings.Secure.ANDROID_ID);

    return android_id;
}