• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Sending an image in an intent to messenger api gets an error

Hello,

I'm trying to send an image (Uri using FIleProvider) to messenger whithin my app. My onClickListener works very fine but when arriving to the messenger layout, it says in a dialog that "Messenger couldn't handle this file". My image is in my drawable file in my android project.

This is how I'm creating my intent, image Uri and my intent :

Code:
File imagePath = new File(getApplicationContext().getFilesDir(), "drawable-hdpi");
                File f = new File(imagePath, "messenger_blue.jpg");
                //File f = new File(Environment.getExternalStorageDirectory()+ File.separator + "messenger_blue.jpg");
                Context context = getApplicationContext();
                Uri uri = FileProvider.getUriForFile(context, "com.guivers.app.guivers.fileprovider", f);
                Log.e("Message", "Uri = "+uri);
                Intent sendIntent = new Intent();
                sendIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
                sendIntent.setType("image/jpg");
                sendIntent.setPackage("com.facebook.orca");
                startActivity(sendIntent);

Here is my provider declaration in my manifest :

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

and my filepaths.xml :

Code:
<paths>
    <external-path name="external_files" path="."/>
</paths>

I think there is a problem when creating my File object or when creatin my Uri file but I don't know what I'm doing wrong...

Thx !
 
my built uri : content://com.guivers.app.guivers.fileprovider/external_files/messenger_blue.jpg
Anyone ? I really need some help !
 
Last edited:
Your images placed into drawable-hdpi folder.
You should use access via android:resources, not external files https://stackoverflow.com/questions/6602417/get-the-uri-of-an-image-stored-in-drawable/36062748
Please find demo project here https://github.com/v777779/aad_20180505
Project uses 4 images in random order and openes Application Chooser to send image.

1. It does not use MyFileProvider to get access to drawable resources.
2. When you address to drawables, it does not matter where they placed exactly "drawable-hdpi" "drawable-mdpi" or somwhere else.
In the path it's necessary use just "drawable/image_name"

Download, open and run. Android Studio 3.1.
Click on Sync Project with Gradle Files, then Build and Run.
 
Last edited:
Back
Top Bottom