发送的消息与内容提供者的类型列之间的冲突

时间:2012-12-05 10:17:05

标签: android sms android-contentprovider

我使用android SmsManager.sendTextMessage(..)发送邮件 但在阅读SMS内容提供者列时,我得到的类型列值1对于已发送的消息应为2,甚至在设备默认消息应用程序上,我发送的消息显示为已接收。

我用来发送消息的代码是

public static final String SMS_URI = "content://sms";
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(address.get(i), null, messagetosend, null, null);
ContentResolver contentResolver = getContentResolver();

ContentValues values = new ContentValues();
values.put(ADDRESS, address.get(i));
values.put(BODY, messagetosend);
contentResolver.insert(Uri.parse(SMS_URI), values);

我正在使用这段代码在Logcat上打印值:

Uri allMessages = Uri.parse("content://sms/");
//Cursor cursor = managedQuery(allMessages, null, null, null, null); Both are same
Cursor cursor = this.getContentResolver().query(allMessages, null, null, null, null);

while (cursor.moveToNext()) {
    for (int i = 0; i < cursor.getColumnCount(); i++) {
        Log.d(cursor.getColumnName(i) + "", cursor.getString(i) + "");
    }
    Log.d("One row finished", "**************************************************");
}

1 个答案:

答案 0 :(得分:1)

尝试更改

public static final String SMS_URI = "content://sms";

public static final String SMS_URI = "content://sms/sent";

你也可以添加

values.put("type", 2);