1

I have built an appWidget which update it's unread sms count for specific contact when a new sms comes in, for that I've registered a contentObserver to monitor incoming sms.

The mySMSObserver class calls the method below for getting the number of unread messages for specific contact, by his ID.

So far so good, the problem is that the query below works fine on the emulator, but when I try that on my android device it allways return 0 unread messages (as shown by Toast).

private static String updateUnreadSMS(String contactID, Context context) {

ContentResolver cr=context.getContentResolver();
//final Uri SMS_INBOX=(Uri.parse("content://mms-sms/conversations"));
//final Uri SMS_INBOX=(Uri.parse("content://mms/inbox"));
final Uri SMS_INBOX=Uri.parse("content://sms/inbox");

Cursor c = cr.query(SMS_INBOX, null, "read = 0 AND person=?", new String[]{contactID}, null);

// get number of unread sms messages
int unreadMessagesCount = c.getCount();

Log.d("DEBUG", "UnreadSMS: "+unreadMessagesCount);
Toast.makeText(context, "updateUnreadSMS "+unreadMessagesCount, Toast.LENGTH_LONG).show();

c.deactivate();
return String.valueOf(unreadMessagesCount); 

}

Is there different query's needed for different devices?

how do I write the same query for "content://mms/inbox"?, Because "person=?" is an illegal field for that query.

Will be glad for your help and advice for solving this problem :)

GalDude33
  • 7,071
  • 1
  • 28
  • 38

1 Answers1

0

Accessing the databases directly might not be the best idea. As locations and data structure might change with different Android versions (It did so with the Calendar storage from 7 => 8). Nevertheless check if your device location and database structure is the same.

For MMS you might take a peek at PduParser used to parse MMS messages and other classes in this folder.

Drejc
  • 14,196
  • 16
  • 71
  • 106
  • Thanks for your comment, I just need some more clarifications please: * How can I check my android device location and database structure is the same? in particular, How can I check my android device location and database structure? * How can I access my databases indirectly? in particular for the SMS database Thanks advanced! – GalDude33 Oct 16 '11 at 18:06
  • As far as I know (correct me if I'm wrong) you can't check locations of storage. You need to know which version of Android stores data where. So the best way is to access the data over Android classes intended for this purpose. And here is the big issue here. Some storages can be accessed this way, some not. This is a big drawback of the Android OS not providing all the needed access. I'm not familiar with SMS storage so you need to take a leap inside the OS guts to find out the where and what. – Drejc Oct 17 '11 at 07:11
  • If you take a look at this question comments you will get the feel: http://stackoverflow.com/questions/4809874/how-to-access-the-sms-storage-on-android – Drejc Oct 17 '11 at 07:31