android-contentresolver

How to remove a contact programmatically in android

被刻印的时光 ゝ 提交于 2019-11-26 22:14:30
I try the following code to remove contact with a specified number: private void removeContact(Context context, String phone) { //context.getContentResolver().delete(Contacts.Phones.CONTENT_URI, phone, null); context.getContentResolver().delete(Contacts.Phones.CONTENT_URI, Contacts.PhonesColumns.NUMBER+"=?", new String[] {phone}); } But I get this exception: java.lang.UnsupportedOperationException: Cannot delete that URL: content://contacts/phones at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:130) at android.database.DatabaseUtils.readExceptionFromParcel

List all camera images in Android

£可爱£侵袭症+ 提交于 2019-11-26 17:27:08
How do you get a list of all camera images of an Android device? Is it through the MediaStore? How? The Gallery app obtains camera images by using a content resolver over Images.Media.EXTERNAL_CONTENT_URI and filtering the results by Media.BUCKET_ID . The bucket identifier is determined with the following code: public static final String CAMERA_IMAGE_BUCKET_NAME = Environment.getExternalStorageDirectory().toString() + "/DCIM/Camera"; public static final String CAMERA_IMAGE_BUCKET_ID = getBucketId(CAMERA_IMAGE_BUCKET_NAME); /** * Matches code in MediaProvider.computeBucketValues. Should be a

Can I perform this Android query with ContentResolver.query()? (LEFT JOIN and CASE)

放肆的年华 提交于 2019-11-26 15:59:55
问题 I am looking to perform the following query (in pseudo-code) on Android: SELECT C.ID, C.NAME, CASE ISNULL(G.GROUPID,0) = 0 THEN 0 ELSE 1 END INGROUP FROM CONTACTS C LEFT JOIN GROUPMEMBERSHIP G ON G.CONTACTID = C.ID AND G.GROUPID = ? I am looking to select the ID and Name of ALL contacts in the system address book, via the default Contacts ContentProvider, along with a 0/1 field indicating whether the contact is a member of group ? . I could of course get all contacts easily enough, then loop

Convert content:// URI to actual path in Android 4.4

别来无恙 提交于 2019-11-26 12:54:14
I tried a solution (see below) that works fine, except in Android 4.4 the call to startActivityForResult() brings up an activity titled "Open from", which has "Recent", "Images", "Downloads" as well as several apps to pick from. When I choose "Images" and try to resolve the returned content URI (using the code below), the call to cursor.getString() returns null. If I choose the exact same file using the Gallery app, cursor.getString() returns a file path. I've only tested this in API levels 16 and 19. Everything works as expected in 16. As far as 19 goes, I have to choose the Gallery or other

How to remove a contact programmatically in android

不羁的心 提交于 2019-11-26 12:19:10
问题 I try the following code to remove contact with a specified number: private void removeContact(Context context, String phone) { //context.getContentResolver().delete(Contacts.Phones.CONTENT_URI, phone, null); context.getContentResolver().delete(Contacts.Phones.CONTENT_URI, Contacts.PhonesColumns.NUMBER+\"=?\", new String[] {phone}); } But I get this exception: java.lang.UnsupportedOperationException: Cannot delete that URL: content://contacts/phones at android.database.DatabaseUtils

How to store large blobs in an android content provider?

一曲冷凌霜 提交于 2019-11-26 10:59:26
问题 I have some large files (images and video) which I need to store in a content provider. The android documentation indicates... If you are exposing byte data that\'s too big to put in the table itself — such as a large bitmap file — the field that exposes the data to clients should actually contain a content: URI string. This is the field that gives clients access to the data file. The record should also have another field, named \"_data\" that lists the exact file path on the device for that

List all camera images in Android

ⅰ亾dé卋堺 提交于 2019-11-26 05:26:04
问题 How do you get a list of all camera images of an Android device? Is it through the MediaStore? How? 回答1: The Gallery app obtains camera images by using a content resolver over Images.Media.EXTERNAL_CONTENT_URI and filtering the results by Media.BUCKET_ID. The bucket identifier is determined with the following code: public static final String CAMERA_IMAGE_BUCKET_NAME = Environment.getExternalStorageDirectory().toString() + "/DCIM/Camera"; public static final String CAMERA_IMAGE_BUCKET_ID =

Android fetch all contact list (name, email, phone) takes more then a minute for about 700 contacts

别来无恙 提交于 2019-11-26 00:55:34
问题 Is there any way to shorten this time? I\'m running with the cursor and takes the name, phone numbers and emails if I remove the phone numbers query from the query loop it ends in 3 seconds any idea how can I improve that query? Maybe I\'m doing something wrong in my query? (Obviously I\'m doing it async but still... it\'s a very long time that a user can\'t wait) Hope someone can share his thoughts about this this is my code ContentResolver cr = getContentResolver(); Cursor cur = cr.query

Android Gallery on Android 4.4 (KitKat) returns different URI for Intent.ACTION_GET_CONTENT

荒凉一梦 提交于 2019-11-25 22:29:04
问题 Before KitKat (or before the new Gallery) the Intent.ACTION_GET_CONTENT returned a URI like this content://media/external/images/media/3951. Using the ContentResolver and quering for MediaStore.Images.Media.DATA returned the file URL. In KitKat however the Gallery returns a URI (via \"Last\") like this: content://com.android.providers.media.documents/document/image:3951 How do I handle this? 回答1: Try this: if (Build.VERSION.SDK_INT <19){ Intent intent = new Intent(); intent.setType("image

Android fetch all contact list (name, email, phone) takes more then a minute for about 700 contacts

笑着哭i 提交于 2019-11-25 19:29:36
Is there any way to shorten this time? I'm running with the cursor and takes the name, phone numbers and emails if I remove the phone numbers query from the query loop it ends in 3 seconds any idea how can I improve that query? Maybe I'm doing something wrong in my query? (Obviously I'm doing it async but still... it's a very long time that a user can't wait) Hope someone can share his thoughts about this this is my code ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); if (cur.getCount() > 0) { while (cur