Example usage for android.app Activity getContentResolver

List of usage examples for android.app Activity getContentResolver

Introduction

In this page you can find the example usage for android.app Activity getContentResolver.

Prototype

@Override
    public ContentResolver getContentResolver() 

Source Link

Usage

From source file:Main.java

public static String GetDeviceID(Activity nativeactivityptr) {
    // This ID will remain constant for this device until a factory reset is performed
    String uuid = Secure.getString(nativeactivityptr.getContentResolver(), Secure.ANDROID_ID);
    return uuid;//from   w  w  w .ja  v a  2s. com
}

From source file:Main.java

public static boolean isAutoBrightness(Activity activity) {
    boolean isAutoAdjustBright = false;
    try {/*from  w w w  . jav a2s.c  o m*/
        isAutoAdjustBright = Settings.System.getInt(activity.getContentResolver(),
                Settings.System.SCREEN_BRIGHTNESS_MODE) == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
    } catch (Settings.SettingNotFoundException e) {
        e.printStackTrace();
    }
    return isAutoAdjustBright;
}

From source file:Main.java

public static int getScreenBrightness(Activity activity) {
    int nowBrightnessValue = 0;

    ContentResolver resolver = activity.getContentResolver();

    try {//from  w  w  w.j av a2s. c  om
        nowBrightnessValue = android.provider.Settings.System.getInt(resolver,
                Settings.System.SCREEN_BRIGHTNESS);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return nowBrightnessValue;
}

From source file:Main.java

public static File uri2File(Activity context, Uri uri) {
    File file;/* ww w  .  j av a  2  s  . com*/
    String[] project = { MediaStore.Images.Media.DATA };
    Cursor actualImageCursor = context.getContentResolver().query(uri, project, null, null, null);
    if (actualImageCursor != null) {
        int actual_image_column_index = actualImageCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        actualImageCursor.moveToFirst();
        String img_path = actualImageCursor.getString(actual_image_column_index);
        file = new File(img_path);
    } else {
        file = new File(uri.getPath());
    }
    if (actualImageCursor != null)
        actualImageCursor.close();
    return file;
}

From source file:Main.java

public static boolean isExistShortcut(Activity context, String authorities) {
    boolean isInstallShortcut = false;
    final ContentResolver cr = context.getContentResolver();

    /*/* w  w  w .ja  v a 2s  .co  m*/
     * if (android.os.Build.VERSION.SDK_INT < 8) { AUTHORITIES =
     * "com.android.launcher.settings"; } else { AUTHORITIES =
     * "com.android.launcher2.settings"; }
     */
    final Uri CONTENT_URI = Uri.parse("content://" + authorities + "/favorites?notify=true");
    Cursor c = cr.query(CONTENT_URI, new String[] { "iconPackage" }, "iconPackage=?",
            new String[] { context.getApplication().getPackageName() }, null);
    if (c != null) {
        if (c.getCount() > 0) {
            isInstallShortcut = true;
        }
        c.close();
    }
    return isInstallShortcut;
}

From source file:Main.java

public static Uri getBitmapFromImageId(Activity activity, int imageId) {
    String[] tinyImgPprojection = { MediaStore.Images.Thumbnails._ID };
    Cursor tinyCursor = Thumbnails.queryMiniThumbnail(activity.getContentResolver(), imageId,
            Thumbnails.MINI_KIND, tinyImgPprojection);
    if (tinyCursor.getCount() != 0) {
        tinyCursor.moveToFirst();/*from www.ja  v a 2  s . c om*/
        int tinyImgId = tinyCursor.getInt(tinyCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID));
        tinyCursor.close();
        return Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                String.valueOf(tinyImgId));
    } else {
        tinyCursor.close();
        return null;
    }
}

From source file:Main.java

public static String resolveFileName(Uri uri, Activity activity) {
    String filename = null;/* w ww . j  a  v  a 2 s  .c  om*/
    String uriString = uri.toString();

    if (uriString.startsWith("content://")) {
        Cursor cursor = null;
        try {
            cursor = activity.getContentResolver().query(uri, null, null, null, null);
            if (cursor != null && cursor.moveToFirst()) {
                String mimeType = MimeTypeMap.getSingleton()
                        .getExtensionFromMimeType(activity.getContentResolver().getType(uri));
                filename = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));

                if (mimeType != null && !filename.endsWith("." + mimeType)) {
                    filename += "." + mimeType;
                }
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    } else if (uriString.startsWith("file://")) {
        filename = (new File(uriString)).getName();
    }
    return filename;
}

From source file:Main.java

public static int getImageIdFromPath(Activity activity, String filePath) {
    String[] projection = { MediaStore.Images.Media._ID };
    Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    String where = String.format("_data like '%s' ", filePath);
    Cursor cursor = MediaStore.Images.Media.query(activity.getContentResolver(), uri, projection, where, null);
    int image_id = 0;
    if (cursor.getCount() != 0) {
        cursor.moveToFirst();//w  w  w  .  j a  va  2  s . c o  m
        image_id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
        cursor.close();
    }
    return image_id;
}

From source file:Main.java

private static void shareAct(Activity act, String fileName, String text) {

    Uri uri = null;/*  w w w.  j ava  2s  .  co m*/

    try {
        FileInputStream input = act.openFileInput(fileName);
        Bitmap bitmap = BitmapFactory.decodeStream(input);
        uri = Uri.parse(MediaStore.Images.Media.insertImage(act.getContentResolver(), bitmap, null, null));
        input.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.setType("image/jpeg");
    act.startActivity(Intent.createChooser(shareIntent, act.getTitle()));
}

From source file:Main.java

/***
 * getIMEI : read the IMEI number of device The IMEI (14 decimal digits plus
 * a check digit) or IMEISV (16 digits) includes information on the origin,
 * model, and serial number of the device. The structure of the IMEI/SV are
 * specified in 3GPP TS 23.003//w  ww.  j  a  v  a 2s.c om
 * 
 * @param activity
 * @return 16 digit IMEI number of device ( padded with zeros)
 */
public static String getIMEI(Activity activity) {
    try {
        TelephonyManager telephonyManager = (TelephonyManager) activity
                .getSystemService(Context.TELEPHONY_SERVICE);
        String imei = telephonyManager.getDeviceId();
        if (imei == null)
            imei = Secure.getString(activity.getContentResolver(), Secure.ANDROID_ID);
        return imei;
    } catch (Exception e) {
    }
    return "EEEE-EEEE-EEEE-E";
}