2010-04-07 42 views
5

Tôi có một người quan sát nội dung thăm dò ý kiến ​​nội dung: // sms/trong android 1.5 để tôi nhận được thông báo về những thay đổi trong cơ sở dữ liệu sms và có thể phản ứng với họ cho phù hợp.ContentObserver trên nội dung: // sms/in 1.6+?

Tuy nhiên trong 1,6 điều này không có tác dụng, uri đã được thay đổi từ nội dung: // sms/thành nội dung khác?

Tôi đã xem nội dung: // mms-sms/popping up trong logcat trên thiết bị 1.6 của tôi nhưng tôi đã thử điều đó và nó không hoạt động.

Đây là mã của tôi

String url = "content://sms/"; 
     Uri uri = Uri.parse(url); 
     getContentResolver().registerContentObserver(uri, true, new MyContentObserver(handler)); 


} 

class MyContentObserver extends ContentObserver { 

    public MyContentObserver(Handler handler) { 

     super(handler); 

    } 

@Override public boolean deliverSelfNotifications() { 
    return false; 
    } 

ContentValues values = new ContentValues(); 


@Override public void onChange(boolean arg0) { 
    super.onChange(arg0); 

    Log.v("SMS", "Notification on SMS observer"); 
    values.put("status", 5); 
    Message msg = new Message(); 
    msg.obj = "xxxxxxxxxx"; 
    int threadId = 0; 
    handler.sendMessage(msg); 

    Uri uriSMSURI = Uri.parse("content://sms/"); 
    Cursor cur = getContentResolver().query(uriSMSURI, null, null, 
       null, null); 
    cur.moveToNext(); 
    String protocol = cur.getString(cur.getColumnIndex("protocol")); 
    Log.d("SMS", "SMS PROTOCOL = " + protocol); 

    if(protocol == null){ 
      Log.d("SMS", "SMS SEND"); 
      threadId = cur.getInt(cur.getColumnIndex("thread_id")); 
      int status = cur.getInt(cur.getColumnIndex("status")); 
      Log.d("SMS", "STATUS = " + status); 


      if(status != 5){ 
      Uri updateUri = ContentUris.withAppendedId(Uri.parse("content://sms/conversations/"), threadId); 
      int rows = getContentResolver().update(updateUri, values, null, null); 
      Log.d("SMS", "ROWS UPDATED = " + rows); 
      Log.d("SMS 2", "STATUS = " + status); 
      } 


      Log.d("SMS", "SMS SEND ID = " + threadId); 

      String textBody = cur.getString(cur.getColumnIndex("body")); 
      String textAddress = cur.getString(cur.getColumnIndex("address")); 
      Log.d("SMS", "SMS SEND ADDRESS= " + textAddress); 
      Log.d("SMS", "SMS SEND BODY= " + textBody); 


    } 
    else{ 
     Log.d("SMS", "SMS RECIEVE"); 

    } 

} 

Trả lời

5

Uri.parse("content://mms-sms")

Hãy đảm bảo tiến trình đang chạy để theo dõi các thay đổi.

Thiết bị của tôi là mốc quan trọng (2.1 update1)

Các vấn đề liên quan