0

manifestI Just want to send the image which is there in my mobile to any android app, I have used this code which is not working. Showing Toast 'file is not supported' while trying to share to whatsapp.

share.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            share_image();
        }
    });

private void share_image()
{
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"/abc.jpg");
    Uri uri = FileProvider.getUriForFile(Main2Activity.this, BuildConfig.APPLICATION_ID + ".provider",file);
    Intent shareIntent = new Intent();
    if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) {
        shareIntent.addFlags( Intent.FLAG_GRANT_WRITE_URI_PERMISSION|Intent.FLAG_GRANT_READ_URI_PERMISSION );
    }
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.setType("image/jpg");
    startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
}


<?xml version="1.0" encoding="utf-8"?> 
<paths xmlns:android="schemas.android.com/apk/res/android"> 
 <external-path name="external_files" path="."/> 
</paths>
Lena Bru
  • 13,521
  • 11
  • 61
  • 126

0 Answers0