I have an application that is having some buttons that implement some features.
Two of them is:
-
Share Image - The images provided by the app which users can share.
-
"Set As" - Users cal also utilize "set as" features (Set As wallpaper, contact picture, etc.).
The app is currently not live, so I tested it's apk on my mobile and 2-3 other Android mobiles. The app is ruing correctly only on my device, but here's what I found,
- "Share" and "Set As" isn't working on emulator - Log cat ERROR shown below.
-
"Share" and "Set As" working perfectly on my Android mobile - Android 5.0. It creates a folder in "Phone Storage" and saves image according to my code shown below.
-
"Share" and "Set As" isn't working on Android 6.0. It is not even creating folder.
"Log cat ERROR FOR Emulator... i..e point 1 above"
- Error after clicking "Share" in Emulator
java.io.FileNotFoundException: "/storage/emulated/0/MyFolder/myimg.png";: open failed: ENOENT (No such file or directory)
-
Error after clicking "Set As" in Emulator
08-22 21:27:34.526 2208-2208/? E/UriImage: got exception decoding bitmap java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.ParcelFileDescriptor android.content.ContentResolver.openFileDescriptor(android.net.Uri, java.lang.String)' on a null object reference at com.android.camera.Util.makeInputStream(Util.java:336) at com.android.camera.Util.makeBitmap(Util.java:307) at com.android.camera.Util.makeBitmap(Util.java:299) at com.android.camera.gallery.UriImage.fullSizeBitmap(UriImage.java:94) at com.android.camera.gallery.UriImage.fullSizeBitmap(UriImage.java:86) at com.android.camera.gallery.UriImage.thumbBitmap(UriImage.java:120) at com.android.camera.CropImage.onCreate(CropImage.java:143) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
Integer Arrays for images
Integer[] imageIDs = {
R.drawable.image1,
R.drawable.image2,
.
.
.
}
SHARE BUTTON code snippet
// Here, I am getting images from the Integer array I created
bitmap = BitmapFactory.decodeResource(getResources(),imageIDs[i]);
File filepath = Environment.getExternalStorageDirectory();
// Creates new folder with name "MyFolder"
File dir = new File(filepath.getAbsolutePath() + "/MyFolder/");
dir.mkdirs();
// Image saves with the following name
File file = new File(dir, "myimg.png");
"Set As" button code snippet
// Here, I am getting images from the Integer array I created
bitmap = BitmapFactory.decodeResource(getResources(),imageIDs[i]);
Rest code I added from the [following thread][1] on Stack Overflow.:
Here, I have added the following path:
String absolutepath="/storage/emulated/0/MyFolder/myimg.png";
