I am working on an SMS application. Everything was smooth until yesterday, when I upgraded my Nexus 4 to Android 4.4, KitKat. Functions such as marking SMS as read / unread and deleting all messages in the stream stopped working. Why is this happening? It works on other Samsung devices (KitKat does not work).
This is my code to mark a message as read or unread:
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(); } }
To delete all messages in the stream, I use:
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);