上下文
我试图从Android中检索MMS数据,我可以从content://mms/中计数MMS,但是当我想获取MMS数据时,它是空的。
问题
首先,我把彩信数成这样:
Uri uri = Telephony.Mms.CONTENT_URI; // content://mms/
Cursor cursor = contentResolver.query(uri, null, null, null, null);
int count = cursor.getCount();假设我有3 MMS,计数等于3,这里没有问题。
现在我想从每个MMS中检索数据,我发现(这里和这里)我必须查询content://mms/part提供者,这就是我所做的。问题是这个游标总是空的,我尝试了许多不同的方法:
Uri uri = Uri.parse("content://mms/part");
String selection = Telephony.Mms.Part.MSG_ID + " = " + id;
Cursor cursor = contentResolver.query(uri, null, selection, null, null);
// OR
Uri uri = Uri.parse("content://mms/part/" + id);
Cursor cursor = contentResolver.query(uri, null, null, null, null);
// OR
Uri uri = Uri.parse("content://mms/" + id "/part");
Cursor cursor = contentResolver.query(uri, null, null, null, null);每次我的光标都是空的。
获取彩信id:
Cursor cursor= contentResolver.query(Telephony.Mms.CONTENT_URI, new String[]{"*"}, null, null, null);
if (cursor!= null) {
if (cursor.getCount() > 0) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
sms = createMmsFromCursor(cursor);
cursor.moveToNext();
}
cursor.close();
}
}然后是createMmsFromCursor(cursor)
private final MMS createMmsFromCursor(Cursor cursor) {
long id = cursor.getLong(cursor.getColumnIndex(Telephony.Mms._ID));
// ...
Map.Entry partValues = getDataFromMms(id);
// ...
return mms;
}getDataFromMms(id)将使用参数中给出的id调用上面的代码(我的问题所在)。
问题
我是否正确地查询内容提供者?还是我使用了错误的提供者Uri?也许根据设备的不同,MMS部件Uri是不同的,如果是的话,我如何总是指向正确的Uri?
发布于 2017-07-21 19:24:37
还不确定你是否找到了答案。这就是我所拥有的,它正在(对我)起作用:
Uri uriMms = Uri.parse("content://mms/");
final String[] projection = new String[]{"*"};
Cursor cursor = contentResolver.query(uriMms, projection, null, null, null);
String id = cursor.getString(cursor.getColumnIndex("_id"));
String selectionPart = "mid=" + id;
Uri uri = Uri.parse("content://mms/part");
Cursor cursor2 = getContentResolver().query(uri, null, selectionPart, null, null);然后执行cursor2.moveToFirst()
https://stackoverflow.com/questions/41699481
复制相似问题