android-contentresolver

Android: SQLite transactions when using ContentResolver

我怕爱的太早我们不能终老 提交于 2019-11-28 15:44:23
The goal: refresh database from XML data The process: Start transaction Delete all existing rows from the tables Per each main element of parsed XML insert row into main table and get PK Per each child of the main element insert record into 2nd table providing FK from the previous step Commit transaction Pretty standard stuff as far as db operations. The problem is that CRUD operations are not done within ContentProvider but rather using ContentResolver so the insert for example looks like resolver.insert(CONTENT_URI, contentValues) . The ContentResolver API doesn't seem to have anything

SMS Messages of a particular number not showing up on other devices Android

老子叫甜甜 提交于 2019-11-28 12:58:48
问题 I am using the Telephony.Sms library to load in received and sent sms messages for the app I am working on. When I set the query selection to null (the third item in the query), it will show all the sent and received sms messages on the different types of phones I have been testing on. Cursor c = cr.query(Telephony.Sms.CONTENT_URI, null, null, null, null); But when I set it to a particular number, on the Samsung S9 phone running on API 27 it is not showing any sms messages. On the Nexus

`getContentResolver().openInputStream(uri)` throws FileNotFoundException

跟風遠走 提交于 2019-11-28 07:23:01
问题 I use this intent to let user select a photo: Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI); startActivityForResult(intent, INTENT_SELECT_PHOTO); And in onActivityResult : Uri uri = data.getData(); InputStream inputStream = getContentResolver().openInputStream(uri); But it throws FileNotFoundException on some android devices. The value of uri : content://media/external/images/media/26467 The exception thrown: java.io.FileNotFoundException: No

What is cursor.setNotificationUri() used for?

a 夏天 提交于 2019-11-28 05:23:28
I did research on how to use ContentProviders and Loaders from this tutorial How I see it: We have an Activity with ListView , SimpleCursorAdapter and CursorLoader . We also implement ContentProvider . In an Activity we can call getContentResolver().insert(URI, contentValues); via a button click. In our implementation of ContentProvider , at the end of insert() method, we call getContentResolver().notifyChange(URI, null); and our CursorLoader will receive message that it should reload data and update UI. Also if we use FLAG_REGISTER_CONTENT_OBSERVER in SimpleCursorAdapter it will also receive

Get Album Art With Album Name Android

跟風遠走 提交于 2019-11-28 05:08:59
I want to display album art with album name in listview. But i am not getting the way to display album art. I have tried from cover art on android . Here is my Code : Cursor cursor = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null, null, null, null); if (cursor == null) { //Query Failed , Handle error. } else if (!cursor.moveToFirst()) { //No media on the device. } else { int titleColumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Albums.ALBUM_ART); int id = cursor.getColumnIndex(android.provider.MediaStore.Audio.Albums.ALBUM_ID); //here value i m getting -1 . for

Android: Distinct and GroupBy in ContentResolver

吃可爱长大的小学妹 提交于 2019-11-28 04:08:55
What would be a sensible way to add DISTINCT and/or GROUPBY to ContentResolver - based queries. Right now I have to create custom URI for each special case. Is there a better way? (I still program for 1.5 as lowest common denominator) You can do nice hack when querying contentResolver, use: String selection = Models.SOMETHING + "=" + something + ") GROUP BY (" + Models.TYPE; Since no one came to answer I'm just going to tell how I solved this. Basically I would create custom URI for each case and pass the criteria in selection parameter. Then inside ContentProvider#query I would identify the

what are uri, contentValues

谁说我不能喝 提交于 2019-11-28 03:50:02
Can anyone explain me about each term that I have used in working with calendar events? Uri event_uri = Uri.parse("content://com.android.calendar/" + "events"); What is uri here, what actually is content, as we can initialize int value to 0? Is it possible to initialize a uri with a default value? Uri reminder_uri = Uri.parse("content://com.android.calendar/" + "reminders"); What signifies these uri? What are the differences between event_uri and reminder_uri ? ContentValues values = new ContentValues(); values.put("calendar_id", 1); values.put("title", str); values.put("description", m

ContentProvider insert() always runs on UI thread?

随声附和 提交于 2019-11-28 03:34:27
I have an app that needs to pull data from a server and insert it into an SQLite database in response to user input. I thought this would be pretty simple - the code that pulls the data from the server is a fairly straightforward subclass of AsyncTask, and it works exactly as I expect it to without hanging the UI thread. I implemented callback functionality for it with a simple interface and wrapped it in a static class, so my code looks like this: MyServerCaller.getFolderContents(folderId, new OnFolderContentsResponseListener() { @Override public void onFolderContentsResponse(final List

Edit name/phone number of contact programmatically

旧时模样 提交于 2019-11-28 03:21:54
问题 I am trying to modify displayed name of a contact programmatically: try { ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI) .withSelection(ContactsContract.CommonDataKinds.Phone._ID + " = ?", new String[] {contact_id}) .withValue(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, "anything") .build()); ContentProviderResult[] result = getContentResolver().applyBatch(ContactsContract.AUTHORITY,

using ContentProviderClient vs ContentResolver to access content provider

元气小坏坏 提交于 2019-11-28 03:05:47
The documentation on Android content providers describes using a ContentResolver , obtained from getContentResolver() , to access the content. However there is also a ContentProviderClient , which can be obtained from getContentResolver().acquireContentProviderClient(authority) . It seems to provide more or less the same methods available in the ContentResolver for accessing content from the provider. When should I use a ContentProviderClient instead of just using the ContentResolver directly? What are the benefits? jcwenger Your android device has many databases, each of which is identified