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();
}
}