2

My code crashes only on Samsung Galaxy tablets (e.g. SM-P601, Android 4.4.2).

The code that crashes is this line:

String path = MediaStore.Images.Media.insertImage(context.getContentResolver(), null, "ShareImage", null);

Another code that fails is just in OnClick method:

Bitmap bm = Bitmap.createBitmap(128, 128, Bitmap.Config.ARGB_8888);
String path = MediaStore.Images.Media.insertImage(MainActivity.this.getContentResolver(), bm, "ShareImage", null);
Log.d("tag", path);

The exception is:

08-07 12:20:41.703 14625-14849/com.mypackage.testapp.testing E/MediaStore﹕ Failed to insert image java.io.FileNotFoundException: No such file or directory at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146) at android.content.ContentProviderProxy.openAssetFile(ContentProviderNative.java:611) at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:925) at android.content.ContentResolver.openOutputStream(ContentResolver.java:672) at android.content.ContentResolver.openOutputStream(ContentResolver.java:648) at android.provider.MediaStore$Images$Media.insertImage(MediaStore.java:937)

  • My context object in this case is application context passed to this method.
  • I have added all the permissions to read and write external storage
  • Again it happens only on specific samsung tablets
  • The issue is not with bitmap, it doesn't work event if I create an empty bitmap.
  • The following code is executed on button click
  • Application does not crash, only exception appears in logs.

This question Doesn't help me.

UPD.

After a few seconds this exception appears:

08-07 12:56:13.038 1841-1852/? E/DatabaseUtils﹕ Writing exception to parcel java.lang.NumberFormatException: Invalid long: "null" at java.lang.Long.invalidLong(Long.java:124) at java.lang.Long.parseLong(Long.java:341) at java.lang.Long.parseLong(Long.java:318) at com.sec.android.gallery3d.provider.GallerySearchDatabase.setTableForTag(GallerySearchDatabase.java:137) at com.sec.android.gallery3d.provider.GallerySearchDatabase.getImages(GallerySearchDatabase.java:559) at com.sec.android.gallery3d.provider.GallerySearchProvider.getFindoSuggest(GallerySearchProvider.java:107) at com.sec.android.gallery3d.provider.GallerySearchProvider.getFindoTagSuggest(GallerySearchProvider.java:111) at com.sec.android.gallery3d.provider.GallerySearchProvider.query(GallerySearchProvider.java:81) at android.content.ContentProvider.query(ContentProvider.java:857) at android.content.ContentProvider$Transport.query(ContentProvider.java:200) at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112) at android.os.Binder.execTransact(Binder.java:404) at dalvik.system.NativeStart.run(Native Method)

Community
  • 1
  • 1
Taras Leskiv
  • 1,835
  • 15
  • 33

1 Answers1

0
public static void fixMediaDir() {
    File sdcard = Environment.getExternalStorageDirectory();
    if (sdcard == null) { return; }
    File dcim = new File(sdcard, "DCIM");
    if (dcim == null) { return; }
    File camera = new File(dcim, "Camera");
    if (camera.exists()) { return; }
    camera.mkdir();
}
Derek Zhu
  • 173
  • 2
  • 11