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

private static String getRealPathFromURI(Context context, Uri contentURI) {
    String result;//  w  w  w .  j  a  v  a 2 s  .c  om
    Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null);
    if (cursor == null) { // Source is Dropbox or other similar local file path
        result = contentURI.getPath();
    } else {
        cursor.moveToFirst();
        int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
        result = cursor.getString(idx);
        cursor.close();
    }
    return result;
}

From source file:Main.java

static int getCardId(Context context) {
    ContentResolver res = context.getContentResolver();
    Cursor c = res.query(Uri.parse("content://media/external/fs_id"), null, null, null, null);
    int id = -1;/*from www . j  ava  2  s . c  om*/
    if (c != null) {
        c.moveToFirst();
        id = c.getInt(0);
        c.close();
    }
    return id;
}

From source file:Main.java

public static void deleteUri(Context context) {
    if (imgUri == null)
        return;//from   w  ww  .  j a v a 2s. co  m
    try {
        context.getContentResolver().delete(imgUri, null, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static Integer getTvhChannelIdFromChannelUri(Context context, Uri channelUri) {
    ContentResolver resolver = context.getContentResolver();

    String[] projection = { Channels._ID, Channels.COLUMN_ORIGINAL_NETWORK_ID };

    // TODO: Handle when more than 1, or 0 results come back
    try (Cursor cursor = resolver.query(channelUri, projection, null, null, null)) {
        while (cursor != null && cursor.moveToNext()) {
            return cursor.getInt(1);
        }//from   www .  j a va 2  s.  c  o m
    }

    return null;
}

From source file:Main.java

public static String getRealPathFromURI(Context context, Uri contentURI) {
    String result = null;/*from  ww w.j  a va  2  s .  c  o m*/
    Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
        result = cursor.getString(idx);
        cursor.close();
    }
    return result;
}

From source file:Main.java

public static Bitmap getBitmap(Context context, Uri uri) throws IOException {
    Bitmap bitmap = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
    return bitmap;
}

From source file:Main.java

public static int getEasyTag(Context context) {
    synchronized (EASY_OPERATION_CLICK_DTATUS) {
        return System.getInt(context.getContentResolver(), EASY_OPERATION_CLICK_DTATUS, UNCLICK);
    }/*from  www  .j a  v a  2 s .co m*/
}

From source file:Main.java

public static int getOrientation(Context context, Uri photoUri) {
    int orientation = 0;
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
    if (cursor != null) {
        if (cursor.getCount() != 1) {
            return -1;
        }/*from   www .  java2 s  .  co m*/
        cursor.moveToFirst();
        orientation = cursor.getInt(0);
        cursor.close();
    }
    return orientation;
}

From source file:Main.java

public static boolean hasContact(Context mContext, String contact) {
    ContentResolver cr = mContext.getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    if (cur.getCount() > 0) {
        while (cur.moveToNext()) {
            String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
            String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            if (Integer.parseInt(
                    cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
                while (pCur.moveToNext()) {
                    String phoneNo = pCur
                            .getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    if (phoneNo.contains(contact) || contact.contains(phoneNo)) {
                        return true;
                    }//from  w  w  w. j a v  a  2 s  .  c o  m
                }
                pCur.close();
            }
        }
    }
    return false;
}

From source file:Main.java

/**
 * Returns the Id for an artist./*from  w  w w  .  j  a  va 2  s  .  co  m*/
 *
 * @param context The {@link Context} to use.
 * @param name The name of the artist.
 * @return The ID for an artist.
 */
public static final long getIdForArtist(final Context context, final String name) {
    Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
            new String[] { BaseColumns._ID }, ArtistColumns.ARTIST + "=?", new String[] { name },
            ArtistColumns.ARTIST);
    int id = -1;
    if (cursor != null) {
        cursor.moveToFirst();
        if (!cursor.isAfterLast()) {
            id = cursor.getInt(0);
        }
        cursor.close();
        cursor = null;
    }
    return id;
}