【问题标题】:Set sms as read in Android在Android中将短信设置为已读
【发布时间】:2011-05-19 13:40:47
【问题描述】:

在我的应用程序中,我只需要读取来自一个数字的短信,当我收到它时,我需要将其设置为自动读取,而不是在短信安卓应用程序中设置它,而是从我的应用程序中设置。我能怎么做? 谢谢!

【问题讨论】:

    标签: android sms


    【解决方案1】:

    让我更新一下:

    ContentValues values = new ContentValues();
    values.put("read",true);
    getContentResolver().update(Uri.parse("content://sms/"),values, "_id="+SmsMessageId, null);
    

    SmsMessageId 是消息的_id,您可以在 SMS 数据库中找到。

    【讨论】:

      【解决方案2】:

      一个简短的例子:

      Uri uri = Uri.parse("content://sms/inbox");
      Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
      while (cursor.moveToNext()) {
        // Retrieve sms
        // see column "address" for comparing
      
        // Then update the sms and set the column "read" to 1
      }
      

      【讨论】:

      • 感谢您的帮助。我有一个问题:while (cursor.moveToNext() && !stato) { String asd = new String(cursor.getBlob(cursor.getColumnIndex("read"))); Toast.makeText(context, asd, Toast.LENGTH_SHORT).show(); } 如果我在 getColumnIndex 中设置地址没有问题,但如果我设置读取或其他列名,它就不起作用。为什么?谢谢!
      • 上次我为 android 写东西大约是一年前。对不起,但我不知道答案。但是有几个用于 sms API 的 Uri。您可以尝试将短信以 content://sms/inbox 的形式写入不同的短信,然后删除收件箱中的旧短信。
      • 您能发布您的解决方案吗?这可能会帮助其他有同样问题的用户。
      • String asd = cursor.getString(cursor.getColumnIndex("read"));忘记发了,不好意思
      • 但是从内容提供者默认短信应用程序更新读取状态后仍然显示此短信未读
      猜你喜欢
      • 1970-01-01
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多