Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从未传递消息的SMS内容URI获取消息_Android_Sms_Uri_Smsmanager - Fatal编程技术网

Android 从未传递消息的SMS内容URI获取消息

Android 从未传递消息的SMS内容URI获取消息,android,sms,uri,smsmanager,Android,Sms,Uri,Smsmanager,我正在开发一个系统应用程序,在该应用程序中,我必须以编程方式从设备发送消息,并在发送后删除该消息。除以下几点外,所有操作都正常 如果消息发送成功,则我可以从SMS内容URI中找到消息,但如果消息失败,则我无法从内容URI中获取消息。我使用以下代码删除消息 public void deleteTheMessage(Context context, String value) { Uri uri = Uri.parse("content://sms"); Cursor c = co

我正在开发一个系统应用程序,在该应用程序中,我必须以编程方式从设备发送消息,并在发送后删除该消息。除以下几点外,所有操作都正常

如果消息发送成功,则我可以从SMS内容URI中找到消息,但如果消息失败,则我无法从内容URI中获取消息。我使用以下代码删除消息

 public void deleteTheMessage(Context context, String value) {
    Uri uri = Uri.parse("content://sms");
    Cursor c = context.getApplicationContext().getContentResolver().query(uri, null, null, null, null);
    try {

        if (c != null) {
            Log.i("deleteTheMessage-->", "  count : " + c.getCount());
        } else {
            Log.i("deleteTheMessage-->", " c null: ");
        }
        while (c.moveToNext()) {
            try {
                if (c != null && c.moveToFirst()) {
                    do {
                        String address = c.getString(2);
                        String id = c.getString(0);
                        long threadId = c.getLong(1);
                        Log.i("deleteTheMessage-->", " address: " + address + " body: " + "" + " threadId: " + threadId + " id: " + id);
                        try {
                            if (address.contains(value)) {
                                int deltedrowcount = context.getApplicationContext().getContentResolver().delete(uri, "thread_id = " + threadId, null);
                                if (deltedrowcount != 0) {
                                    Log.i("deleteTheMessage-->", " SMS has Deleted successfully " + deltedrowcount);
                                }
                                Log.i("deleteTheMessage-->", " body  " + address);
                            }
                        } catch (Exception e) {
                            Log.i("deleteTheMessage-->", "SmsWriteOpUtil Exception in deleting SMS  " + e.getMessage());
                        }

                    } while (c.moveToNext());
                }
            } catch (Exception e) {
                Log.i("deleteTheMessage-->", "c.moveToNext() Exception in deleting SMS" + e.getMessage());
            }
        }
    } catch (Exception e) {
        Log.i("deleteTheMessage-->", " try Exception in deleting SMS: " + e.getMessage());
    } finally {
        c.close();
    }
}
我想在11345之前删除邮件地址,请参见下面的屏幕截图。


最后,我用下面的代码找到了删除未送达的消息的解决方案

        long threadId = Telephony.Threads.getOrCreateThreadId(context, phoneNumber);
        LogMgr.i("deleteByThreadID-->" + "  threadId : " + threadId);
        int threadIdDeletedCount = context.getContentResolver().delete(Uri.parse("content://sms"), "thread_id =?", new String[]{String.valueOf(threadId)});
        LogMgr.i("deleteByThreadID: --> threadIdDeletedCount " + threadIdDeletedCount);

phoneNumber这是发送消息的号码。

您测试的是哪个Android版本?谢谢您的回复。我正在为Android 8.1开发,但我也在6.0中进行了测试,它不起作用。你的应用程序是否设置为默认的消息传递应用程序?是的,它将是一个系统应用程序。如果只查询那个数字,会得到什么结果?也就是说,
查询(uri,null,“address=?”,新字符串[]{“11345”},null)
。很好的解决方法。不过,我仍然想知道,为什么不能在常规查询中获取这些消息。