0

On Oreo version of Android the app crashes when I share the image, but it works on Android versions below Oreo.

Here is the code:

File f = new File(Environment.getExternalStorageDirectory() + File.separator + "bala.jpg");
    try {
        f.createNewFile();
        FileOutputStream fo = new FileOutputStream(f);
        fo.write(bytes.toByteArray());
        fo.close();
    } catch (Exception e) {
    }
Uri uri = Uri.fromFile(f);
    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType("image/*");
    String shareBody = "In Tweecher, My highest score with screen shot";
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello");
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
    sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);

    startActivity(Intent.createChooser(sharingIntent, "Share via"
Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
  • You could have a look at the crash log as it will provide relevant details. There's some guidance in [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this). – Markus Kauppinen Aug 27 '20 at 08:13
  • **do you check the Permissions??** at first you should check the Permissions you could help from this library Dexter --> [dexter library](https://github.com/Karumi/Dexter) – mohammad kazemienjad Aug 27 '20 at 19:57
  • yes, i provide the permission – Sakthi Balan Aug 28 '20 at 08:26
  • I use provider for API22 emulator in Android Studio to send an image with built-in Messaging APP and it crash "Unfortunate, Messaging has stopped" I use catch Throwable but it does not return anything so I suppose it is the built-in Messaging APP Problem. However, when that warning appear, both Messaging and my APP disappeared. I dont think I can control or know what intent people will use... – Raii Nov 05 '22 at 13:03

0 Answers0