SMS Sent/Delivered Broadcast Receiver [duplicate]

你离开我真会死。 提交于 2019-12-11 00:57:12

问题


Possible Duplicate:
Broadcast Receiver for Sent SMS

I am currently detecting when an SMS is received through a broadcast receiver like so:

<receiver android:name=".gathering.SMSNode">
    <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
</receiver>

Is there a similar broadcast receiver for detecting when a message is sent?


回答1:


ContentResolver contentResolver = getContentResolver();
Handler handler = new Handler();
m_SMSObserver = new SMSObserver(handler);
contentResolver.registerContentObserver(Uri.parse("content://sms"),
true, m_SMSObserver);

And this code for separating send/receive events

Uri uriSMSURI = Uri.parse("content://sms");
Cursor cur = this.getContentResolver().query(uriSMSURI, null, null,
null, null);
cur.moveToNext();
String protocol = cur.getString(cur.getColumnIndex("protocol"));
if(protocol == null)
        onSMSSend();            
else
        onSMSReceive(); 

Check the following url for reference:

http://www.mail-archive.com/android-developers@googlegroups.com/msg27154.html



来源:https://stackoverflow.com/questions/14008991/sms-sent-delivered-broadcast-receiver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!