I got following Exception while sharing images using FileProvider. Following is the code I used to.
{
ArrayList<Uri> files = new ArrayList<Uri>();
files.add(getImageUriFromCache(context,bitmap,fileName));
}
private void startSharingIntent(ArrayList<Uri> files,String caption){
Intent i=new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
i.setType("image/png");
i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
i.putExtra(Intent.EXTRA_SUBJECT, "my app share");
i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
i.putExtra(Intent.EXTRA_TEXT,caption);
i.putExtra(Intent.EXTRA_TITLE,caption);
context.startActivity(Intent.createChooser(i, "Tital"));
}
public Uri getImageUriFromCache(Context inContext, Bitmap inImage , String fileId) throws IOException{
File cachePath = new File(inContext.getFilesDir() , "images/");
cachePath.mkdirs(); // don't forget to make the directory
File newFile = new File(cachePath, "im"+fileId+"_post.png");
newFile.setReadable(true, false);
FileOutputStream stream = new FileOutputStream(newFile); // overwrites this image every time
inImage.compress(Bitmap.CompressFormat.PNG, 100, stream);
stream.close();
Uri contentUri = FileProvider.getUriForFile(inContext, "com.xx.xx.fileprovider", newFile);
return contentUri;
}
Detail stack trace of exception is as follows.
08-11 09:02:47.943: I/Choreographer(428): Skipped 31 frames! The application may be doing too much work on its main thread.
08-11 09:02:48.343: D/dalvikvm(1832): GC_FOR_ALLOC freed 287K, 8% free 4686K/5048K, paused 25ms, total 25ms
08-11 09:02:48.353: I/dalvikvm-heap(1832): Grow heap (frag case) to 5.200MB for 583180-byte allocation
08-11 09:02:48.403: D/dalvikvm(1832): GC_FOR_ALLOC freed 32K, 8% free 5223K/5620K, paused 35ms, total 40ms
08-11 09:02:48.693: E/CursorWindow(1832): Failed to read row 0, column 0 from a CursorWindow which has 1 rows, 0 columns.
08-11 09:02:48.713: W/dalvikvm(1832): threadid=20: thread exiting with uncaught exception (group=0xb1ac1b90)
08-11 09:02:48.773: E/AndroidRuntime(1832): FATAL EXCEPTION: ThumbnailManager-1
08-11 09:02:48.773: E/AndroidRuntime(1832): Process: com.android.mms, PID: 1832
08-11 09:02:48.773: E/AndroidRuntime(1832): java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
08-11 09:02:48.773: E/AndroidRuntime(1832): at android.database.CursorWindow.nativeGetLong(Native Method)
08-11 09:02:48.773: E/AndroidRuntime(1832): at android.database.CursorWindow.getLong(CursorWindow.java:507)
08-11 09:02:48.773: E/AndroidRuntime(1832): at android.database.CursorWindow.getInt(CursorWindow.java:574)
08-11 09:02:48.773: E/AndroidRuntime(1832): at android.database.AbstractWindowedCursor.getInt(AbstractWindowedCursor.java:69)
08-11 09:02:48.773: E/AndroidRuntime(1832): at android.database.CursorWrapper.getInt(CursorWrapper.java:102)
08-11 09:02:48.773: E/AndroidRuntime(1832): at com.android.mms.ui.UriImage.getOrientation(UriImage.java:546)
08-11 09:02:48.773: E/AndroidRuntime(1832): at com.android.mms.util.ThumbnailManager$ThumbnailTask.requestDecode(ThumbnailManager.java:490)
08-11 09:02:48.773: E/AndroidRuntime(1832): at com.android.mms.util.ThumbnailManager$ThumbnailTask.onDecodeOriginal(ThumbnailManager.java:439)
08-11 09:02:48.773: E/AndroidRuntime(1832): at com.android.mms.util.ThumbnailManager$ThumbnailTask.getBitmap(ThumbnailManager.java:342)
08-11 09:02:48.773: E/AndroidRuntime(1832): at com.android.mms.util.ThumbnailManager$ThumbnailTask.run(ThumbnailManager.java:252)
08-11 09:02:48.773: E/AndroidRuntime(1832): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-11 09:02:48.773: E/AndroidRuntime(1832): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-11 09:02:48.773: E/AndroidRuntime(1832): at java.lang.Thread.run(Thread.java:841)
08-11 09:02:48.793: W/ActivityManager(377): Force finishing activity com.android.mms/.ui.ComposeMessageActivity
Images are shared correctly when I choose email to share, but failed when I select messaging. Please assist.