ContentObserver on content://sms/ in 1.6+ ?

All your problems with Audio, Video and Images.

ContentObserver on content://sms/ in 1.6+ ?

Postby Draffodx » Wed Apr 07, 2010 10:15 am

Hi,

I have a content observer that polls content://sms/ in android 1.5 so that I get notified of changes in the sms database and can react to them accordingly.

However in 1.6 this doesn't work, has the uri been changed from content://sms/ to something else?

I have seen content://mms-sms/ popping up in the logcat on my 1.6 device but I have tried that and it doesn't work.

Here is my code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String url = "content://sms/";
  2.  
  3.                 Uri uri = Uri.parse(url);
  4.  
  5.                 getContentResolver().registerContentObserver(uri, true, new MyContentObserver(handler));
  6.  
  7.                
  8.  
  9.                
  10.  
  11.     }
  12.  
  13.    
  14.  
  15.     class MyContentObserver extends ContentObserver {
  16.  
  17.        
  18.  
  19.         public MyContentObserver(Handler handler) {
  20.  
  21.                
  22.  
  23.                 super(handler);
  24.  
  25.                
  26.  
  27.         }
  28.  
  29.  
  30.  
  31.     @Override public boolean deliverSelfNotifications() {
  32.  
  33.         return false;
  34.  
  35.         }
  36.  
  37.    
  38.  
  39.     ContentValues values = new ContentValues();
  40.  
  41.        
  42.  
  43.        
  44.  
  45.     @Override public void onChange(boolean arg0) {
  46.  
  47.         super.onChange(arg0);
  48.  
  49.        
  50.  
  51.          Log.v("SMS", "Notification on SMS observer");
  52.  
  53.          values.put("status", 5);
  54.  
  55.         Message msg = new Message();
  56.  
  57.         msg.obj = "xxxxxxxxxx";
  58.  
  59.         int threadId = 0;
  60.  
  61.         handler.sendMessage(msg);
  62.  
  63.        
  64.  
  65.         Uri uriSMSURI = Uri.parse("content://sms/");
  66.  
  67.         Cursor cur = getContentResolver().query(uriSMSURI, null, null,
  68.  
  69.                      null, null);
  70.  
  71.         cur.moveToNext();
  72.  
  73.         String protocol = cur.getString(cur.getColumnIndex("protocol"));
  74.  
  75.         Log.d("SMS", "SMS PROTOCOL = " + protocol);
  76.  
  77.  
  78.  
  79.         if(protocol == null){
  80.  
  81.                Log.d("SMS", "SMS SEND");
  82.  
  83.                threadId = cur.getInt(cur.getColumnIndex("thread_id"));
  84.  
  85.                int status = cur.getInt(cur.getColumnIndex("status"));
  86.  
  87.                Log.d("SMS", "STATUS = " + status);
  88.  
  89.              
  90.  
  91.                
  92.  
  93.                if(status != 5){
  94.  
  95.                Uri updateUri = ContentUris.withAppendedId(Uri.parse("content://sms/conversations/"), threadId);
  96.  
  97.                int rows = getContentResolver().update(updateUri, values, null, null);
  98.  
  99.                Log.d("SMS", "ROWS UPDATED = " + rows);
  100.  
  101.                Log.d("SMS 2", "STATUS = " + status);
  102.  
  103.                }
  104.  
  105.                
  106.  
  107.              
  108.  
  109.                Log.d("SMS", "SMS SEND ID = " + threadId);
  110.  
  111.                
  112.  
  113.                String textBody = cur.getString(cur.getColumnIndex("body"));
  114.  
  115.                String textAddress  = cur.getString(cur.getColumnIndex("address"));
  116.  
  117.                Log.d("SMS", "SMS SEND ADDRESS= " + textAddress);
  118.  
  119.                Log.d("SMS", "SMS SEND BODY= " + textBody);
  120.  
  121.              
  122.  
  123.  
  124.  
  125.         }
  126.  
  127.         else{
  128.  
  129.                 Log.d("SMS", "SMS RECIEVE");  
  130.  
  131.  
  132.  
  133.         }
  134.  
  135.  
  136.  
  137.     }
Parsed in 0.042 seconds, using GeSHi 1.0.8.4
Draffodx
Master Developer
Master Developer
 
Posts: 205
Joined: Wed Nov 12, 2008 2:31 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 15 guests