需要检测android中发送的短信吗
我知道这个问题很老,可能是重复的,但我有一个基于它的特定查询,我仍在试图找到解决方案 据我所知,需要检测android中发送的短信吗,android,android-contentprovider,android-sms,Android,Android Contentprovider,Android Sms,我知道这个问题很老,可能是重复的,但我有一个基于它的特定查询,我仍在试图找到解决方案 据我所知,ContentObserveron-URIcontent://sms将在数据发生更改时触发。 我试过了 还有更多 据我所知,这只能由内容提供商实现,没有广播来处理。也content://sms/sent在以下位置不起作用 contentResolver.registerContentObserver(Uri.parse("content://sms/sent"), true, observer);
ContentObserver
on-URIcontent://sms
将在数据发生更改时触发。
我试过了
还有更多
据我所知,这只能由内容提供商实现,没有广播来处理。也content://sms/sent
在以下位置不起作用
contentResolver.registerContentObserver(Uri.parse("content://sms/sent"), true, observer);
我接收每个消息数据的onChange
,无论其短信是否已发送、接收或删除。因此,根据android和其他stackoverflow链接的文档,我发现使用了as比较方法
所以我的支票是
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Uri uriSMSURI = Uri.parse("content://sms");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);
cur.moveToFirst();
String id = cur.getString(cur.getColumnIndex("_id"));
String protocol = cur.getString(cur.getColumnIndex("protocol"));
Log.d(TAG, "protocol = " + protocol);
int type = cur.getInt(cur.getColumnIndex("type"));
Log.d(TAG, "onChange: type = " + type);
// I have even tried with protocol == null check.
if (type == 2 && smsChecker(id)) {
Log.d(TAG, "Sent sms");
}
cur.close();
}
private boolean smsChecker(String smsId) {
boolean flagSMS = true;
if (smsId.equals(lastSmsId)) {
flagSMS = false;
}
else {
lastSmsId = smsId;
}
return flagSMS;
}
所以我这里的问题是,如果我删除任何消息或触发一条传出消息,我会在我的HTC phone-LOS上收到类型2(有时对于传入消息,我也会看到类型==2)
我怎样才能分开这个onChange请求,因为我特别寻找短信发送的更改