有没有办法使用特定的 SMS 在 android 上打开消息传递活动?
问问题
6056 次
4 回答
9
threadId
应该是您要查看的 SMS/MMS 线程的 id
Intent defineIntent = new Intent(Intent.ACTION_VIEW);
defineIntent.setData(Uri.parse("content://mms-sms/conversations/"+threadId));
myActivity.startActivity(defineIntent);
这是我发现的最简单的方法
于 2010-05-11T08:43:07.747 回答
4
试试这个
int req_thread_id;
Uri mSmsinboxQueryUri = Uri.parse("content://sms"));
Cursor cursor1 = getContentResolver().query(
mSmsinboxQueryUri,
new String[] { "_id", "thread_id", "address", "person", "date",
"body", "type" }, null, null, null);
startManagingCursor(cursor1);
if (cursor1.getCount() > 0)
{
while (cursor1.moveToNext())
{
int thread_id = cursor1.getInt(1);
String address; = cursor1.getString(cursor1
.getColumnIndex(columns[0]));
if("your desired no".equals(address)
req_thread_id = thread_id;
}
}
Intent defineIntent = new Intent(Intent.ACTION_VIEW);
defineIntent.setData(Uri.parse("content://mms-sms/conversations/"+req_thread_id));
myActivity.startActivity(defineIntent);
于 2011-12-29T06:03:22.597 回答
2
我从 Messaging 应用程序的源代码(第 311-315 行)中挖出了这个,所以我很确定它会起作用,但我没有任何经验。
// threadId should be the id of the sms/mms thread you want to view
long threadId = 0;
Intent i = new Intent("com.android.mms");
i.setData(
Uri.withAppendedPath(
i.getData(), Long.toString(threadId)
)
);
i.setAction(Intent.ACTION_VIEW);
于 2009-09-11T23:27:04.230 回答
0
此片段来自已接受答案中的评论。将方法发布在这里以供后代使用。
public static long findThreadIdFromAddress(Context context, String address) {
if (address == null)
return 0;
String THREAD_RECIPIENT_QUERY = "recipient";
Uri.Builder uriBuilder = THREAD_ID_CONTENT_URI.buildUpon();
uriBuilder.appendQueryParameter(THREAD_RECIPIENT_QUERY, address);
long threadId = 0;
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(
uriBuilder.build(),
new String[] { Contacts._ID },
null, null, null);
if (cursor != null && cursor.moveToFirst()) {
threadId = cursor.getLong(0);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return threadId;
}
于 2014-07-02T11:22:19.780 回答