//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
)
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