【问题标题】:Unable to delete SMS programmatically无法以编程方式删除 SMS
【发布时间】:2015-10-21 14:29:49
【问题描述】:

我尝试过从 SMS 中删除全部或部分消息的变体,包括但不限于线程 id、id、where 子句等。 Android 清单反映了读写权限。 我尝试了来自收件箱等的 SMS 内容的变体。 似乎没有什么可以删除记录。

这是最后一次迭代:

    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();
        }

【问题讨论】:

  • 你在哪个版本的 Android 上测试这个?
  • 不,您使用的设备/模拟器是什么版本的 Android
  • 4.4.2 api 19,也在物理设备 Galaxy S5 上运行

标签: android sms


【解决方案1】:

Android 4.4 Kitkat 引入了changes in SMS handling,现在只允许默认 SMS 应用程序对 SMS 数据库进行写入访问 - 所有其他应用程序在尝试写入时都会静默失败。

【讨论】:

  • 谢谢!我更新了清单,重新运行了应用程序,并相应地删除了所有内容。
猜你喜欢
  • 2016-11-30
  • 2012-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多