使用广播接收器,它可以完美地执行。
答案 0 :(得分:-1)
在清单文件中添加权限,例如
<uses-permission android:name="android.permission.RECEIVE_SMS"android:protectionLevel="signature" />
<uses-permission android:name="android.permission.READ_SMS" />
然后添加意图过滤器:
<receiver android:name="com.aquadeals.seller.services.SmsReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
获取所有短信:
TelephonyProvider telephonyProvider = new TelephonyProvider(context);
List<Sms> smses = telephonyProvider.getSms(Filter.ALL).getList();
删除短信:
通过将读取sms主体的值存储到共享首选项并仅删除共享优先权的那些来实现。
Uri inboxUri = Uri.parse("content://sms/inbox");
int count = 0;
Cursor c = getContentResolver().query(inboxUri , null, null, null, null);
while (c.moveToNext()) {
try {
// Delete the SMS
String pid = c.getString(0); // Get id;
String uri = "content://sms/" + pid;
// uri.
count =getContentResolver().delete(Uri.parse(uri),
null, null);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
}
}
所有Android内容提供商都包括:通讯录,通话记录,日历,... Full doc with all options