當我查詢「content:// sms /」內容提供者並從地址欄中提取信息時;我總是收到郵件是「從」或「發送給」的電話號碼。如果我收到一條消息,則地址是來自其他人的電話號碼。當我發送消息時,地址就是我發送的消息。內容://短信/地址欄不總是返回「發件人」號碼
如何區分「content:// sms /」文件夾中的郵件是發送郵件還是收到郵件而不查詢相應的收件箱/發送文件夾?
Uri uri = Uri.parse("content://sms/");
String[] columns = new String[] { "_id", "thread_id", "address", "person", "date", "body" };
String selection = "thread_id = " + threadId;
String sortOrder = "date DESC";
String limit = "LIMIT " + String.valueOf(mItemsOnPage);
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String deviceNumber = tm.getLine1Number();
Cursor cursor = getContentResolver().query(uri, columns, selection, null,
sortOrder + " " + limit);
if (cursor != null) {
cursor.moveToLast();
while (!cursor.isBeforeFirst()) {
long messageId = cursor.getLong(0);
String address = cursor.getString(2);
long date = cursor.getLong(4);
String body = cursor.getString(5);
long person = cursor.getLong(3);
cursor.moveToPrevious();
}
}
cursor.close();
我意識到此列,但認爲這將MMS和SMS區分。非常感謝。 – Justin 2012-02-18 17:44:52
你會碰巧知道第5類消息是什麼嗎? – Justin 2012-02-20 19:48:17
@Justin請參閱:https://developer.android.com/reference/android/provider/Telephony.TextBasedSmsColumns.html#MESSAGE_TYPE_ALL所有相關的常量 – Ben 2015-09-29 08:39:07