我目前正在检测通过广播接收器收到短信的时间如下:
<receiver android:name=".gathering.SMSNode">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
是否有类似的广播接收器用于检测何时发送消息?
答案 0 :(得分: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