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:org.godotengine.godot.Utils.java

public static String getDeviceId(Activity activity) {
    String android_id = Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);

    String deviceId = md5(android_id).toUpperCase();

    return android_id;
}

From source file:Main.java

@SuppressLint("SimpleDateFormat")
public static Uri launchActivityForResult(Activity activity, Intent intent, int requestCode) {
    SimpleDateFormat timeStampFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
    String filename = timeStampFormat.format(new Date());
    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE, filename);
    Uri photoUri = activity.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
    activity.startActivityForResult(intent, requestCode);
    return photoUri;
}

From source file:com.microsoft.rightsmanagement.sampleapp.App.java

/**
 * Gets the file name from a content URI.
 * /*from w w w .  j a va  2  s .  c o m*/
 * @param activity the activity
 * @param uri the uri
 * @return the file name from the content uri.
 */
public static String getFileNameFromContent(Activity activity, Uri uri) {
    String fileName = null;
    if (uri != null) {
        Cursor c = activity.getContentResolver().query(uri, null, null, null, null);
        c.moveToFirst();
        final int fileNameColumnId = c.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
        if (fileNameColumnId >= 0) {
            fileName = c.getString(fileNameColumnId);
        }
    }
    // Emulator attachment files are stored in another place.
    if (fileName == null) {
        String[] proj = { MediaColumns.DISPLAY_NAME };
        Cursor cursor = activity.getContentResolver().query(uri, proj, null, null, null);
        if (cursor != null && cursor.getCount() > 0) {
            int columnIndex = cursor.getColumnIndexOrThrow(MediaColumns.DISPLAY_NAME);
            cursor.moveToFirst();
            fileName = cursor.getString(columnIndex);
        }
    }
    return fileName;
}

From source file:org.jared.synodroid.ds.utils.Utils.java

public static Uri moveToStorage(Activity a, Uri uri) {
    ContentResolver cr = a.getContentResolver();
    try {/* w  w  w. jav a  2s . com*/
        InputStream is = cr.openInputStream(uri);

        File path = Environment.getExternalStorageDirectory();
        path = new File(path, "Android/data/org.jared.synodroid.ds/cache/");
        path.mkdirs();

        String fname = getContentName(cr, uri);
        File file = null;
        if (fname != null) {
            file = new File(path, fname);
        } else {
            file = new File(path, "attachment.att");
        }

        BufferedInputStream bis = new BufferedInputStream(is);

        /*
         * Read bytes to the Buffer until there is nothing more to read(-1).
         */
        ByteArrayBuffer baf = new ByteArrayBuffer(50);
        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }

        /* Convert the Bytes read to a String. */
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(baf.toByteArray());
        fos.close();

        return uri = Uri.fromFile(file);
    } catch (FileNotFoundException e) {
        // do nothing
    } catch (IOException e) {
        // do nothing
    }

    return null;
}

From source file:Main.java

public static ArrayList<String> getAllShownImagesPath(Activity activity) {
    Uri uri;/*from   ww w .j a  v  a 2s  . c o  m*/
    Cursor cursor;
    int column_index_data, column_index_folder_name;
    ArrayList<String> listOfAllImages = new ArrayList<String>();
    String absolutePathOfImage = null;
    uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

    String[] projection = { MediaStore.MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME };

    cursor = activity.getContentResolver().query(uri, projection, null, null, null);

    column_index_data = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
    column_index_folder_name = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
    while (cursor.moveToNext()) {
        absolutePathOfImage = cursor.getString(column_index_data);

        listOfAllImages.add(absolutePathOfImage);
    }
    return listOfAllImages;
}

From source file:Main.java

/**
 * Get Bitmap from Uri//from  w ww.  j  av  a  2  s.c o  m
 *
 * @param uri Uri to get Bitmap
 * @return
 * @throws FileNotFoundException
 * @throws IOException
 */
public static Bitmap getImageFromUri(Activity activity, Uri uri, File file) throws IOException {

    BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options();
    onlyBoundsOptions.inJustDecodeBounds = true;
    onlyBoundsOptions.inDither = true;//optional
    onlyBoundsOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional
    if (file != null) {
        BitmapFactory.decodeFile(file.getAbsolutePath(), onlyBoundsOptions);
    } else {
        InputStream input = activity.getContentResolver().openInputStream(uri);
        BitmapFactory.decodeStream(input, null, onlyBoundsOptions);
        input.close();
    }

    if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1))
        return null;

    float scale = activity.getResources().getDisplayMetrics().density;
    int pHeight = (int) (activity.getResources().getConfiguration().screenHeightDp * scale + 0.5f);
    int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight
            : onlyBoundsOptions.outWidth;

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

    int REQUIRED_SIZE = activity.getResources().getDisplayMetrics().heightPixels / 2;

    /**/
    int Scale = 1;
    while (onlyBoundsOptions.outWidth / Scale / 2 >= REQUIRED_SIZE
            && onlyBoundsOptions.outHeight / Scale / 2 >= REQUIRED_SIZE) {
        Scale *= 2;
    }
    /**/

    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
    bitmapOptions.inSampleSize = Scale;//getPowerOfTwoForSampleRatio(ratio);
    bitmapOptions.inDither = true;//optional
    bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional

    Bitmap bitmap;
    if (file != null) {
        bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), bitmapOptions);
    } else {
        InputStream input = activity.getContentResolver().openInputStream(uri);
        bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions);
        input.close();
    }

    return bitmap;
}

From source file:com.google.android.gm.ay.java

public static void a(final Activity activity, final Account account, final String s) {
    final Uri build = Uri
            .parse(c.a(activity.getContentResolver(), "gmail_context_sensitive_help_url",
                    "http://support.google.com/mail"))
            .buildUpon().appendPath("topic").appendPath(activity.getString(2131297018)).build();
    final Locale default1 = Locale.getDefault();
    final Uri build2 = build.buildUpon()
            .appendQueryParameter("hl", default1.getLanguage() + "_" + default1.getCountry().toLowerCase())
            .build();//from  w  w w .  j a  v a2  s.  co m
    final GoogleHelp a = GoogleHelp.gi(s).L(build2).h(GoogleHelp.j(activity)).z(g((Context) activity, account))
            .a(2131558417, activity.getString(2131296702), h((Context) activity, build2))
            .a(2131558418, activity.getString(2131297062),
                    h((Context) activity,
                            Uri.parse(c.a(activity.getContentResolver(), "gmail_privacy_policy_url",
                                    "https://www.google.com/policies/privacy/"))))
            .a(2131558419, activity.getString(2131297061),
                    new Intent((Context) activity, (Class) LicenseActivity.class))
            .a(2131558420, activity.getString(2131297063),
                    h((Context) activity, Uri.parse(c.a(activity.getContentResolver(),
                            "gmail_terms_of_service_url", "https://www.google.com/policies/terms/"))));
    if (account != null) {
        a.d(account.uf());
    }
    new a(activity).e(a.QA());
}

From source file:io.digibyte.tools.util.Utils.java

public static boolean isUsingCustomInputMethod(Activity context) {
    if (context == null)
        return false;
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm == null) {
        return false;
    }/*from w  ww  .  j av  a 2s  .  c  o m*/
    List<InputMethodInfo> mInputMethodProperties = imm.getEnabledInputMethodList();
    final int N = mInputMethodProperties.size();
    for (int i = 0; i < N; i++) {
        InputMethodInfo imi = mInputMethodProperties.get(i);
        if (imi.getId().equals(Settings.Secure.getString(context.getContentResolver(),
                Settings.Secure.DEFAULT_INPUT_METHOD))) {
            if ((imi.getServiceInfo().applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.dwdesign.tweetings.fragment.BaseDialogFragment.java

public ContentResolver getContentResolver() {
    final Activity activity = getActivity();
    if (activity != null)
        return activity.getContentResolver();
    return null;/*w  w  w  . j a v a2  s.  c  o  m*/
}

From source file:at.flack.MainActivity.java

public static final Bitmap fetchThumbnail(Activity context, String number) {
    Integer id = fetchThumbnailId(context, number);
    if (id == null)
        return null;
    final Uri uri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, id);
    final Cursor cursor = context.getContentResolver().query(uri, SMSItem.PHOTO_BITMAP_PROJECTION, null, null,
            null);/*www .  j  a  va  2 s .c  o  m*/

    try {
        Bitmap thumbnail = null;
        if (cursor.moveToFirst()) {
            final byte[] thumbnailBytes = cursor.getBlob(0);
            if (thumbnailBytes != null) {
                thumbnail = BitmapFactory.decodeByteArray(thumbnailBytes, 0, thumbnailBytes.length);
            }
        }
        return thumbnail;
    } finally {
        cursor.close();
    }
}