The file format is not supported - When a photo is send on WhatsApp

it's JU picture it's JU · Apr 27, 2017 · Viewed 29.4k times · Source
        //Share image to all
        share = (Button)findViewById(R.id.facebook_app_id);
        share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Uri imageUri = Uri.parse("android.resource://" + getPackageName() +"/drawable/"+imageRes);
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("image/*");

                intent.putExtra(Intent.EXTRA_STREAM, imageUri);
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                startActivity(Intent.createChooser(intent , "Share"));


            }

        });

I am trying to build a photo-sharing app. Facebook, Messenger, Skype work perfectly but Whatsapp and Viber show an Error (The file format is not supported)

Answer

albeee picture albeee · Apr 27, 2017

Try setting the content type in the share Intent as image/png. As you said above, that may or may not work for all apps.

The reason is You can not directly share a uri from you apps internal storage (of course the resourses of your app will be always in the internal storage)

There are two ways of achieving this..

Copy your image to external storage then share it from there. See this

Write a Content Provider to share image. For that refer Create and Share a File from Internal Storage