Google的Messenger应用在发送彩信时未附加图片

时间:2016-08-11 05:39:54

标签: android android-intent telephony mms

我无法在Google的Messenger应用中发送带有图片的彩信。 虽然某些Android设备默认安装此SMS应用程序,并且当我使用Intent发送彩信而不是它不起作用时。

问题是ToNumber和MMS内容设置,但图片未附加在此应用上。

注意: 我已经在我的设备上设置了MMS APN设置,我已经使用三星s4,摩托罗拉G4 Plus这样的应用程序检查了多个设备。

这是我目前使用的代码。

 String toNumbers = "comma seperated mobile numbers";

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) 
    {
        String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(getActivity()); 

        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.putExtra("address", toNumbers);
        sendIntent.setPackage("com.android.mms");
        //Uri uri = Uri.fromFile(new File(getContext().getExternalFilesDir(""), "image.png"));

        File imagePath = new File(getFilesDir(), "images");
        File newFile = new File(imagePath, "image.png");
        Uri uri = getUriForFile(this, "packagename", newFile);

        File file = new File(contentUri.getPath());
        if (file.exists()) {
            //Do something
            Log.d("TAG","Exist");
        }
        sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
        sendIntent.setType("image/png");
        sendIntent.putExtra("sms_body", getString(R.string.sms_body, HostName));
        if (defaultSmsPackageName != null)
        {
            sendIntent.setPackage(defaultSmsPackageName);
        }
        startActivityForResult(sendIntent, Constants.SEND_SMS_REQUEST);


    }
    else 
    {
        Intent smsIntent = new Intent(android.content.Intent.ACTION_VIEW);
        smsIntent.putExtra("address", toNumbers);
        smsIntent.setPackage("com.android.mms");
        Uri uri = Uri.fromFile(new File(getContext().getExternalFilesDir(""), "image.png"));
        smsIntent.putExtra(Intent.EXTRA_STREAM, uri);
        smsIntent.setType("image/png");
        smsIntent.putExtra("sms_body", getString(R.string.sms_body, HostName));
        startActivityForResult(smsIntent, Constants.SEND_SMS_REQUEST);
    }

file_paths.xml

<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path
    name="files"
    path="images/" />

</paths>

manifeast.xml

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="packagename"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths" />


    </provider>

1 个答案:

答案 0 :(得分:1)

file_paths.xml manifest.xml 与您的代码中的相同。

创建内容uri

File imagePath = new File(getFilesDir(), "images");
File newFile = new File(imagePath, "image.png");
Uri contentUri = FileProvider.getUriForFile(this, "packagename", newFile);

检查内容uri:

ImageView imageView = (ImageView) findViewById(R.id.imageview);
//Your image should be displayed
imageView.setImageURI(contentUri);

创建意图:

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Text to send");
sendIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
sendIntent.setType("image/png");

测试解决方案:

a)Galaxy S4,Android 5.0,Messenger ver:1.9.036

b)模拟器:Nexus 5,Android 6.0,Messaging ver:1.0.001