How to Use Sms Content Provider? Where Are the Docs

Using new Telephony content provider to read SMS

It looks like you would be able to use this class to get it working. The package is Telephony.Sms.Conversations.

Although the following code uses the content provider method, this is now an official API added in API Level 19 (KitKat) for reading the SMS messages.

public List<String> getAllSmsFromProvider() {
List<String> lstSms = new ArrayList<String>();
ContentResolver cr = mActivity.getContentResolver();

Cursor c = cr.query(Telephony.Sms.Inbox.CONTENT_URI, // Official CONTENT_URI from docs
new String[] { Telephony.Sms.Inbox.BODY }, // Select body text
null,
null,
Telephony.Sms.Inbox.DEFAULT_SORT_ORDER); // Default sort order

int totalSMS = c.getCount();

if (c.moveToFirst()) {
for (int i = 0; i < totalSMS; i++) {
lstSms.add(c.getString(0));
c.moveToNext();
}
} else {
throw new RuntimeException("You have no SMS in Inbox");
}
c.close();

return lstSms;
}

What is the URI for SMS Draft Content Provider?

Content Provider URI for SMS is commonly

   content://sms/...

and for SMS Drafts it is

   content://sms/drafts/

SMS missing from content provider results on Android Marshmallow

It seems the messages that are missing are in fact not SMS, but RCS messages. These are not stored in the SMS Provider, and therefore will not be returned from any queries to it, though messaging apps on devices that support RCS are likely to display them all together seamlessly. This would explain why it appears that your query results are incomplete.

RCS (Rich Communication Services) is basically enhanced SMS/MMS, offering functionalities such as real-time one-to-one and group chat, video calling, content sharing, etc., in addition to regular ol' text messaging. Currently, there is no standard API in Android for this, though Google is reportedly in the process of adopting this as an eventual replacement for SMS/MMS. I could find no official word on how this will be integrated or deployed, however.

Not every carrier offers RCS, and those that do have dedicated, proprietary apps and APIs to handle it. These, of course, are going to be different for each carrier/manufacturer, and even the branding varies widely. Most call it joyn, whereas T-Mobile brands it as Advanced Messaging. As RCS becomes more commonplace, it should become more standardized, but supporting RCS in your app currently will require specialized components and setups.

Access message inbox without Content UrI (content//:sms)

it works well in my milestone (sdk update 2.1)

 public List<String> getSms() {
Uri mSmsQueryUri = Uri.parse("content://sms/inbox");
List<String> messages = new ArrayList<String>();
Cursor cursor = null;
try {
cursor = mContentResolver.query(mSmsQueryUri, null, null, null, null);
if (cursor == null) {
Log.i(TAG, "cursor is null. uri: " + mSmsQueryUri);
return messages;
}

for (boolean hasData = cursor.moveToFirst(); hasData; hasData = cursor.moveToNext()) {
final String body = cursor.getString(cursor.getColumnIndexOrThrow("body"));
messages.add(body);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
} finally {
cursor.close();
}
return messages;
}

Please make sure you have the read sms permission:

<uses-permission android:name="android.permission.READ_SMS"></uses-permission>


Related Topics



Leave a reply



Submit