简体   繁体   English

使用Android中的Intent打开带有附件的MMS消息传递默认屏幕

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

My requirement is that I have to open directly (without app chooser) messaging default android screen from my application with to,body and vcf attachment. 我的要求是我必须直接打开我的应用程序中带有to,body和vcf附件的消息传递默认android屏幕(无应用选择器)。 I am using below two methods(Approach). 我正在使用以下两种方法(方法)。 But in first approach, attachment is coming but multiple app chooser screen comes first then I have to choose Messaging app. 但是在第一种方法中,附件来了,但是首先出现了多个应用选择器屏幕,然后我必须选择消息传递应用。

In second approach, default messaging app is opening but attachment (.vcf) file is not coming. 在第二种方法中,默认消息传递应用程序正在打开,但是附件(.vcf)文件不存在。 Please advice. 请指教。 Below is the code. 下面是代码。

Approach 1: 方法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);
    }

Approach 2: 方法二:

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

I got the solution finally as below. 我终于得到了解决方案,如下所示。 The main issue was that 1. Add ClassName in Intent and 2. Use file path starting from file:// and put it into Uri.parse() 主要问题是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