2

可能重复:
已发送 SMS 的广播接收器

我目前正在检测何时通过广播接收器接收到 SMS,如下所示:

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

是否有类似的广播接收器用于检测何时发送消息?

4

1 回答 1

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

这段代码用于分离发送/接收事件

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

检查以下网址以供参考:

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

于 2012-12-23T06:11:10.607 回答