to share an image and a text with the other app, I did that:
File path = getExternalFilesDir(Environment.DIRECTORY_PICTURES+"eVendeur");
if (!path.exists()){
path.mkdir();
}
File root = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File cachePath = new File(root.getAbsolutePath()+"/eVendeur/"+id_produit+".jpg");
try {
cachePath.createNewFile();
FileOutputStream outputStream = new FileOutputStream(cachePath);
myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("*/*");
share.putExtra(Intent.EXTRA_TEXT, "my text");
if(Build.VERSION.SDK_INT>=24){
try{
Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
m.invoke(null);
}catch(Exception e){
e.printStackTrace();
}
}
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(cachePath));
view.getContext().startActivity(Intent.createChooser(share, "Share:"));
it works but on some devices, im getting :
java.io.IOException: No such file or directory....
what should i change in the code for it to work?
thanks in advance