Unable to share image to Messaging app with FileProvider

375 Views Asked by At

Sharing an image to Gmail works fine. When trying to share to default "Messages" app on Nexus S, the "You can't add this picture to your message" toast is displayed and image is not attached to a message. Android version 4.1.2.

Here is my implementation:

AndroidManifest:

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

filepaths.xml:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path name="external_files" path="."/>
</paths>

Intent:

    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

    Context context = MyApplication.getInstance().getApplicationContext();
    String authority = context.getString(R.string.provider_authorities);
    Uri uri = FileProvider.getUriForFile(context, authority, file)

    sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
    sendIntent.setType("image/png");
    String titleForChooser = getString(R.string.app_chooser_title);
    Intent chooser = Intent.createChooser(sendIntent, titleForChooser);
    startActivityForResult(chooser, APPS_CHOOSER_REQUEST_CODE);

File is put to the following path: content://com.package.name.fileprovider/external_files/Android/data/com.package.name/files/share_im/155047.png

What is wrong?

0

There are 0 best solutions below