I'm using this code to share a screenshot of the score:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/png");
Uri image = Uri.parse(Environment.getExternalStorageDirectory().toString() + "/sharescore.png");
try {
// create bitmap screen capture
View v1 = v.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(image.getPath());
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
} catch (Throwable e) {
// Several error may come out with file handling or OOM
e.printStackTrace();
}
sharingIntent.putExtra(Intent.EXTRA_STREAM, image);
startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_via)));
It works fine for Whatsapp Twitter etc but not for snapchat and Instagram also when I use the "imgae/jpeg" type. It results in the error "selected image cant be opened". How can I make this work for snapchat and instagram.
Im using this code for Instagram and works fine:
I hope this snippet help you.
They Problem was, that I saved the screenshot to the sd-card, but snapchat doesnt have the permission to read files from the external storage. I had to use the app Directory that can only be accesed by my app and had to change the permissions with my own fileprovider (com.test.fileprovider) so that snapchat can acess it. Here is the Code: