문제

특정 SM으로 Android에서 메시징 활동을 열 수있는 방법이 있습니까?

도움이 되었습니까?

해결책

threadId 보고 싶은 SMS/MMS 스레드의 ID 여야합니다.

Intent defineIntent = new Intent(Intent.ACTION_VIEW); 
defineIntent.setData(Uri.parse("content://mms-sms/conversations/"+threadId));  
myActivity.startActivity(defineIntent);

이것이 내가 찾은 가장 간단한 방법입니다

다른 팁

이 시도

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);

나는 이것을 메시징 앱의 소스에서 파헤 쳤다.라인 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);

이 스 니펫은 허용 된 답변의 의견에서 나온 것입니다. 후손을위한 방법을 여기에 게시합니다.

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;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top