contentObserver على المحتوى: // sms/في 1.6+؟
-
25-09-2019 - |
سؤال
لدي مراقب للمحتوى يحتوى على محتوى الاستطلاعات: // sms/in Android 1.5 حتى يتم إخطار التغييرات في قاعدة بيانات SMS ويمكنني الرد عليها وفقًا لذلك.
ومع ذلك ، في 1.6 هذا لا يعمل ، هل تم تغيير URI من المحتوى: // sms/إلى شيء آخر؟
لقد رأيت المحتوى: // mms-sms/ظهرت في logcat على جهازي 1.6 لكنني جربت ذلك ولا يعمل.
ها هو الكود الخاص بي
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");
}
}
المحلول
Uri.parse("content://mms-sms")
يرجى التأكد من أن العملية تعمل لمراقبة التغييرات.
جهازي معلمي (2.1 تحديث 1)
لا تنتمي إلى StackOverflow