How to use SMS content provider? Where are the docs?

In addition to those u can see the list of fields in sms content provider by using following code: private void displaySmsLog() { Uri allMessages = Uri.parse(“content://sms/”); //Cursor cursor = managedQuery(allMessages, null, null, null, null); Both are same Cursor cursor = this.getContentResolver().query(allMessages, null, null, null, null); while (cursor.moveToNext()) { for (int i = 0; i … Read more

Multiple Apps use same content provider

It’s an old question, but I was looking at doing something similar recently. With the Build flavours, its really straight forward now. Specify the BuildConfigField in the gradle file: productFlavors { free { applicationId “com.example.free” buildConfigField ‘String’, ‘AUTHORITY’, ‘”com.example.free.contentprovider”‘ } paid { applicationId “com.example.paid” buildConfigField ‘String’, ‘AUTHORITY’, ‘”com.example.paid.contentprovider”‘ } Specify the provider authority in the … Read more

What are the semantics of withValueBackReference?

This question relates to batch operation on a content provider. The example is modified from this related question. When creating a batch of operations first create a list of operations to perform using: ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(); then apply them to the content provider using the applyBatch method. ContentProviderResult[] results = this.getContentResolver().applyBatch(FooBar.AUTHORITY, operations); That … Read more

What is the use of private Content Providers?

It automatically schedules all your server-side and synchronization DB access in a background thread. However, in your application frontend, the Content Resolver/Provider will normally execute queries/transactions from the UI thread by default. You must perform all transactions asynchronously (i.e. using a CursorLoader) to ensure that your application runs smoothly on the UI side It localizes … Read more

How do I get the _count in my content provider?

If you are using contentProvider then you have to do it like count(*) AS count. If you use cursor.getCount(), that would not be as efficient as the above approach. With cursor.getCount() you are fetching all the records just to get counts. The entire code should look like following – Cursor countCursor = getContentResolver().query(CONTENT_URI, new String[] … Read more

Create and Share a File from Internal Storage

It is possible to expose a file stored in your apps private directory via a ContentProvider. Here is some example code I made showing how to create a content provider that can do this. Manifest <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.providertest” android:versionCode=”1″ android:versionName=”1.0″> <uses-sdk android:minSdkVersion=”11″ android:targetSdkVersion=”15″ /> <application android:label=”@string/app_name” android:icon=”@drawable/ic_launcher” android:theme=”@style/AppTheme”> <activity android:name=”.MainActivity” android:label=”@string/app_name”> <intent-filter> <action android:name=”android.intent.action.MAIN” /> … Read more

CursorLoader not updating after data change

Did you call setNotificationUri(ContentResolver cr, Uri uri) on the Cursor before returning it in ContentProvider.query()? And did you call getContext().getContentResolver().notifyChange(uri, null) in the ‘insert’ method of your ContentProvider? EDIT: To get a ContentResolver call getContext().getContentResolver() in your ContentProvider.

Possible to use multiple authorities with FileProvider?

My solution to this problem has actually been to avoid relying on a single FileProvider parsing multiple authorities. While this doesn’t directly address the question as stated, I’m posting it for posterity. I updated my library to leverage an empty subclass of FileProvider, so that the library’s updated manifest provider entry is now: <provider android:name=”.flow.email.screenshot.BugShakerFileProvider” … Read more