如何在Android 5.0棒棒糖或Kitkat中删除特定的收件箱消息? [英] How to delete particular inbox message in Android version 5.0 lollipop or in Kitkat?

查看:105
本文介绍了如何在Android 5.0棒棒糖或Kitkat中删除特定的收件箱消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在删除电话号码任务的特定短信。当我在motog或Android 5.0版的移动设备上进行测试时。我无法删除特定号码的短信。我的代码段如下。

I am making to delete particular sms of phone number task. when I am testing in motog or Android version 5.0's mobile. I can't delete particular number's sms. My code snippet is below.

public void deleteSMS(Context context,String number) {
    try {
        Log.d("","Deleting SMS from inbox");
        Uri uriSms = Uri.parse("content://sms/inbox");
        Cursor c = context.getContentResolver().query(uriSms,
                new String[] { "_id", "thread_id", "address",
                        "person", "date", "body" }, "address = '"+number+"'", null, null);

        if (c != null && c.moveToFirst()) {
            do {
                long id = c.getLong(0);
                long threadId = c.getLong(1);
                String address = c.getString(2);
                String body = c.getString(5);
                Toast.makeText(getApplicationContext(),"SMS with id: " + threadId +" Number:- " +address,Toast.LENGTH_LONG).show();
                Log.d("", "SMS with id: " + threadId +" Number:- " +address);
                if ( address.equals(number)) {
                    Log.d("", "Deleting SMS with id: " + threadId);
                    context.getContentResolver().delete(
                            Uri.parse("content://sms/" + id), null, null);
                }
            } while (c.moveToNext());
        }
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(),"Could not delete SMS from inbox ",Toast.LENGTH_LONG).show();
        Log.e("", "Could not delete SMS from inbox: " + e.getMessage());
    }
}


推荐答案

之后4.4您不得从收件箱中删除任何短信,除非您的应用是默认短信应用

After 4.4 you are not allowed to delete any sms messages from inbox unless your app is the "default sms app"


从Android 4.4开始,系统设置允许用户选择默认短信应用。选择后,只有默认的SMS应用程序才能写入SMS提供商,只有默认的SMS应用程序在用户收到SMS时会广播SMS_DELIVER_ACTION广播,或者在用户收到MMS时会广播WAP_PUSH_DELIVER_ACTION。默认的SMS应用程序负责在接收或发送新消息时将详细信息写入SMS Provider。

Beginning with Android 4.4, the system settings allow users to select a "default SMS app." Once selected, only the default SMS app is able to write to the SMS Provider and only the default SMS app receives the SMS_DELIVER_ACTION broadcast when the user receives an SMS or the WAP_PUSH_DELIVER_ACTION broadcast when the user receives an MMS. The default SMS app is responsible for writing details to the SMS Provider when it receives or sends a new message.

未被选择为默认SMS应用程序的其他应用程序只能读取
的SMS提供商
...

Other apps that are not selected as the default SMS app can only read the SMS Provider...

您可以在此处看到更多信息
只是提到了以下重要部分:

You can see More info here just mentioned the important part below:


如果您的应用旨在充当默认的短信应用,则您的应用没有被选择为默认情况下,了解您应用程序的限制并适当禁用功能非常重要。尽管系统在您的应用不是默认的SMS应用时将已发送的SMS消息写入SMS Provider,但它不会写入已发送的MMS消息,并且您的应用无法写入SMS Provider进行其他操作,例如将消息标记为草稿,将其标记为已读,将其删除,等等。

if your app is designed to behave as the default SMS app, then while your app is not selected as the default, it's important that you understand the limitations placed upon your app and disable features as appropriate. Although the system writes sent SMS messages to the SMS Provider while your app is not the default SMS app, it does not write sent MMS messages and your app is not able to write to the SMS Provider for other operations, such as to mark messages as draft, mark them as read, delete them, etc.

这篇关于如何在Android 5.0棒棒糖或Kitkat中删除特定的收件箱消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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