0

I'm trying to add share feature to my app I tried this code and it's work fine on Android 5.0 and Android 7.0 but when I run my app on Android 6.0.1 I get this error

Process: maa.myapp, PID: 20195 java.lang.NullPointerException: uriString at android.net.Uri$StringUri.(Uri.java:476) at android.net.Uri$StringUri.(Uri.java:466) at android.net.Uri.parse(Uri.java:438) at maa.myapp.full$2$2.onResourceReady(full.java:122) at maa.myapp.full$2$2.onResourceReady(full.java:118)

Here is my code:

Glide.with(getApplicationContext())
                    .load(url)
                    .asBitmap()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(new SimpleTarget<Bitmap>() {
                        @Override
                        public void onResourceReady(Bitmap resource, GlideAnimation<?super Bitmap> glideAnimation) {
                            String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), resource,"title", null);
                            Uri bitmapUri = Uri.parse(bitmapPath);
                            Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.setType("image/png");
                            intent.putExtra(Intent.EXTRA_STREAM, bitmapUri);
                            startActivity(Intent.createChooser(intent, "Share"));
                            lt.success();
                        }
                    });
Zoe
  • 27,060
  • 21
  • 118
  • 148
S.Queroane
  • 77
  • 2
  • 12
  • 1
    Is either `bitmapPath` or `resource` null when running on Android 6.0.1? – Maxwell Oct 18 '17 at 20:28
  • @Maxwell i get the error in `Uri bitmapUri = Uri.parse(bitmapPath);` so i think is `bitmapPath` – S.Queroane Oct 18 '17 at 20:31
  • 1
    Does this answer provide any useful insight? https://stackoverflow.com/a/18422186/1102687 – Maxwell Oct 18 '17 at 20:45
  • 1
    Or perhaps this one: https://stackoverflow.com/a/35283353/1102687 This seems to be more related to your situation since it's dealing with 6.0 (Marshmallow) – Maxwell Oct 18 '17 at 20:46
  • @Maxwell thanks so much I followed this tutorial [Android Tutorial: Photo app – Save bitmap to SD card or Share via Intent](http://www.christianpeeters.com/android-tutorials/android-tutorial-photo-app-save-bitmap-to-sd-card-or-share-via-intent/) Where he saved the image first and then share it – S.Queroane Oct 18 '17 at 21:02

0 Answers0