簡體   English   中英

使用Android中的Intent打開帶有附件的MMS消息傳遞默認屏幕

[英]Open MMS messaging default screen with attachment using intent in android

我的要求是我必須直接打開我的應用程序中帶有to,body和vcf附件的消息傳遞默認android屏幕(無應用選擇器)。 我正在使用以下兩種方法(方法)。 但是在第一種方法中,附件來了,但是首先出現了多個應用選擇器屏幕,然后我必須選擇消息傳遞應用。

在第二種方法中,默認消息傳遞應用程序正在打開,但是附件(.vcf)文件不存在。 請指教。 下面是代碼。

方法1:

public static void sendMMS(Context ctx,String firstname,String send_to,String body,String vcard)
    {

        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setType("text/x-vcard");
        sendIntent.putExtra("address", send_to);
        sendIntent.putExtra("sms_body", body);

      File file1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),firstname+".vcf");
        sendIntent.putExtra(Intent.EXTRA_STREAM,
                Uri.fromFile(file1));
        ((Activity) ctx).startActivity(sendIntent);
    }

方法二:

private void sendMMS()
{
    Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
    smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
    smsIntent.setType("vnd.android-dir/mms-sms");
     File file1 = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),"file.vcf");
     smsIntent.putExtra(Intent.EXTRA_STREAM,
                Uri.fromFile(file1));
    smsIntent.setData(Uri.parse("sms:" + "XXXXXXXXXXX")); 
    startActivity(smsIntent);
}

我終於得到了解決方案,如下所示。 主要問題是1.在Intent中添加ClassName並2.使用從file://開頭的文件路徑並將其放入Uri.parse()

Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
        sendIntent.putExtra("sms_body", body); 
        sendIntent.putExtra("address", send_to);
        sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Test.vcf"));
        sendIntent.setType("text/x-vcard");
        startActivity(sendIntent);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM