如何删除Android 5.0版棒棒糖或Kitkat中的特定收件箱邮件?

如何删除Android 5.0版棒棒糖或Kitkat中的特定收件箱邮件?,第1张

概述我正在删除电话号码任务的特定短信.当我在motog或Android5.0版的手机上测试时.我无法删除特定号码的短信.我的代码片段如下.publicvoiddeleteSMS(Contextcontext,Stringnumber){try{Log.d("","DeletingSMSfrominbox");UriuriSms=Uri.parse("

我正在删除电话号码任务的特定短信.当我在motog或Android 5.0版的手机上测试时.我无法删除特定号码的短信.我的代码片段如下.

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之后,除非您的应用是“默认短信应用”,否则不允许从收件箱中删除任何短信.

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.

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

You can see More info here
刚才提到了以下重要部分:

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中的特定收件箱邮件?全部内容,希望文章能够帮你解决如何删除Android 5.0版棒棒糖或Kitkat中的特定收件箱邮件?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1115735.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存