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

查看:18
本文介绍了如何删除 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 提供程序.

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 提供商...

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 应用运行,那么虽然您的应用未被选为默认应用,但重要的是您了解应用的限制并酌情禁用功能.虽然您的应用程序不是默认的短信应用程序,但系统将发送的短信写入短信提供程序,但它不会写入发送的彩信,您的应用程序无法写入短信提供程序进行其他操作,例如将消息标记为草稿、标记为已读、删除等

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天全站免登陆