android - 将 SMS 消息标记为已读/未读或删除在 KitKat 中不起作用的消息

标签 android sms android-4.4-kitkat

我一直在开发短信应用程序。一切都很顺利,直到昨天我将 Nexus 4 更新到 Android 4.4 KitKat。将短信标记为已读/未读以及删除线程中的所有消息等功能已停止工作。为什么会发生这种情况?它适用于其他三星设备(不运行 KitKat)。

这是我将消息标记为已读或未读的代码:

public static void markRead(final Context context, final Uri uri,
            final int read) {
        Log.d(TAG, "markRead(" + uri + "," + read + ")");
        if (uri == null) {
            return;
        }
        String[] sel = Message.SELECTION_UNREAD;
        if (read == 0) {
            sel = Message.SELECTION_READ;
        }
        final ContentResolver cr = context.getContentResolver();
        final ContentValues cv = new ContentValues();
        cv.put(Message.PROJECTION[Message.INDEX_READ], read);
        try {
            cr.update(uri, cv, Message.SELECTION_READ_UNREAD, sel);
        } catch (IllegalArgumentException e) {
            Log.e(TAG, "failed update", e);
            Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
        }
}

为了删除线程中的所有消息,我使用:

public static void deleteMessages(final Context context, final Uri uri,
            final int title, final int message, final Activity activity) {

        Log.i(TAG, "deleteMessages(..," + uri + " ,..)");
        final Builder builder = new Builder(context);
        builder.setTitle(title);
        builder.setMessage(message);
        builder.setNegativeButton(android.R.string.no, null);
        builder.setPositiveButton(android.R.string.yes,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog,
                            final int which) {
                        final int ret = context.getContentResolver().delete(
                                uri, null, null);
                        Log.d(TAG, "deleted: " + ret);
                        if (activity != null && !activity.isFinishing()) {
                            activity.finish();
                        }
                        if (ret > 0) {
                            Conversation.flushCache();
                            Message.flushCache();
                            SmsReceiver.updateNewMessageNotification(context,
                                    null);
                            // adapter.notifyDataSetChanged();
                        }
                        try {
                            testFromFragment(context);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
        builder.show();
}

最佳答案

在 Android 4.4 中,短信方面发生了一些变化。其中一个事实是,只有注册为默认短信应用程序的应用程序才具有对提供商的写入权限。

Check here有关短信更改的简短介绍。

Check this link以便更深入地了解。本节解释了您的应用需要满足哪些标准才能成为默认消息应用。

And here's官方有趣的东西。

因此,如果您的应用不是默认消息应用,这就是指定功能停止工作的原因。

<小时/>

可以在 answer here 中找到默认提供程序限制的可能解决方法。 .

关于android - 将 SMS 消息标记为已读/未读或删除在 KitKat 中不起作用的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57307561/

相关文章:

android - 在 Android 中步行/驾驶时更新位置标记并在 Google map 上绘制路径

java - android Map错误膨胀类 fragment

android - 在个人应用程序中打开 facebook 登录屏幕,而不是在设备浏览器中

c# - 使用 asp.net C# 通过 GSM 调制解调器发送短信

android - 自动恢复到以前的默认短信应用程序

android - 多行 EditText 聚焦时收缩

android - 通过 Intent 发送短信并知道短信是否已发送

c# - 从 ASP.NET 网站发送短信

android - Dumpsys meminfo中出现的 “Lost RAM”背后的概念是什么?

android - Android 中的不同 toast 消息