5

我有一个内容观察器,它在 android 1.5 中轮询 content://sms/ 以便我收到有关 sms 数据库更改的通知,并可以对它们做出相应的反应。

但是在 1.6 中这不起作用,uri 是否已从 content://sms/ 更改为其他内容?

我已经看到 content://mms-sms/ 在我的 1.6 设备上的 logcat 中弹出,但我已经尝试过了,但它不起作用。

这是我的代码

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");  

    }

}
4

1 回答 1

5

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

请确保进程正在运行以监控更改。

我的设备是里程碑(2.1 update1)

于 2010-06-11T07:35:32.617 回答