0

So I have this method to share via email social media, Whatsapp, etc.

But when I click the button that is connected with the share method, it doesn't work. Can you guys help me?

There is a pop up like toast that says like this: file//storage/emulated/0/Android/data/com.project.myapp/cache/sample.png exposed beyond app through ClipData.Item.getUri().

This is my Share method:

  private void shareImage() {
    try {
        //Get title, description, price, category and save in string
        String s = detTitleTv.getText().toString() + "\n" + detDescriptionTv.getText().toString()
                + "\n" + detPriceTv.getText().toString() + "\n" + detCategoryTv.getText().toString()
                + "\n" + detLocationTv.getText().toString();

        File file = new File(getExternalCacheDir(), "sample.png");
        FileOutputStream fOut = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
        fOut.flush();
        fOut.close();
        file.setReadable(true,false);
        //Intent to share image and text
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Intent.EXTRA_TEXT, s);//Put the text
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        intent.setType("image/png");
        startActivity(Intent.createChooser(intent,"Share via"));

    } catch (Exception e) {
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
    }
}
Amrutha Saj
  • 1,408
  • 16
  • 35
  • https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed – Janaaaa Jul 20 '18 at 03:37
  • https://stackoverflow.com/questions/48117511/exposed-beyond-app-through-clipdata-item-geturi - This one has the exact error like yours but the root cause is same. Use a file provider as detailed in the previous link that i shared. – Janaaaa Jul 20 '18 at 03:41

0 Answers0