【问题标题】:Marking SMS messages as read/unread or deleting messages not working in KitKat将 SMS 消息标记为已读/未读或删除在 KitKat 中不起作用的消息
【发布时间】:2018-05-11 14:41:20
【问题描述】:

我一直在开发一个 SMS 应用程序。直到昨天,当我将 Nexus 4 更新为 Android 4.4 KitKat 时,一切都很顺利。诸如将 SMS 标记为已读/未读以及删除线程中的所有消息等功能已停止工作。为什么会这样?它适用于其他三星设备(不运行 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 sms android-4.4-kitkat


【解决方案1】:

在 Android 4.4 中,SMS 发生了一些变化。其中之一是只有注册为默认 SMS 应用程序的应用程序才具有对提供程序的写入权限。

Check here 简要介绍 SMS 的更改。

Check this link 进行更深入的了解。这一个解释了您的应用需要满足哪些标准才能成为默认消息传递应用。

And here's官方好玩的东西。

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


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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 2018-01-05
    相关资源
    最近更新 更多