阅读短信,生成命中,然后以编程方式删除 [英] Read SMS ,generate hit and then delete programatically

查看:100
本文介绍了阅读短信,生成命中,然后以编程方式删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用广播接收器执行完美。

Using broadcast receiver it's execute perfectly.

推荐答案

在清单文件中添加权限,如

Add permissions in manifest file like

<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>






获取所有短信:


Get all SMS:

TelephonyProvider telephonyProvider = new TelephonyProvider(context);
List<Sms> smses = telephonyProvider.getSms(Filter.ALL).getList();






删除短信:


Deleting SMS:

通过将read sms body的值存储为sharedpreference来执行,只删除共享引用的值。

Do it by storing the value of read sms body to sharedpreference and delete only those who are in sharedprefrence.

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内容提供商,如:联系人,通话记录,日历,... 具有所有选项的完整文档

All Android content providers like: Contacts, Call logs, Calendar, ... Full doc with all options

这篇关于阅读短信,生成命中,然后以编程方式删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆