Unable to delete SMS programmatically

蓝咒 提交于 2019-12-12 15:53:52

问题


I have tried variations on deleting all or some messages from the SMS, including but not limited to thread id, id, where clause, etc. Android manifest reflects read and write permissions. I tried with variations on the SMS content, from inbox etc. Nothing seems to delete the record.

Here is the last iteration:

    Cursor c = getApplicationContext().getContentResolver().query(Uri.parse("content://sms/"), null, null, null,null);
    try {
          while (c.moveToNext()) {
             int Id = c.getInt(0);
             String pid = c.getString(0);
            // String uri = "content://sms/conversations/" + threadId;
             String strUriAll = "content://sms/" + pid;//SMS_ALL
             Log.d("URI is ", strUriAll);
             getApplicationContext().getContentResolver().delete(Uri.parse(strUriAll), null, null);
          //   getApplicationContext().getContentResolver().delete(Uri.parse(strUriAll), null, null);
          }

        }catch(Exception e){
             Log.e(this.toString(),"Error deleting sms",e);
        }finally {
          c.close();
        }


回答1:


Android 4.4 Kitkat introduced changes in SMS handling where now only the default SMS app is allowed write access to the SMS database - all other apps silently fail when attempting to write.



来源:https://stackoverflow.com/questions/24168336/unable-to-delete-sms-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!