0

In my Android app, I am using the camera by using the android.media.action.IMAGE_CAPTURE intent. I then use ExifInterface because I need to send the miniature of the photo to my server:

ExifInterface exif = new ExifInterface(GetinnersActivity.this.getExternalFilesDir(null).toString() + File.separator + fileName);
                                byte[] thumbnail = exif.getThumbnail();
                                String miniature = Base64.encodeToString(thumbnail,Base64.DEFAULT); //This line crashes on Nexus 5

I don't have any problem with others phones, but Nexus 5 crashes when trying to execute the last line of code I provided. The Nexus 5 is running on Android 5.1.1. In my Android Manifest,

<uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="19" />

I was wondering if that's due to some known bug with Nexus 5 or if I am doing something wrong.

06-21 19:49:55.748: E/AndroidRuntime(29256): java.lang.NullPointerException: Attempt to get length of null array
06-21 19:49:55.748: E/AndroidRuntime(29256):    at android.util.Base64.encode(Base64.java:494)
06-21 19:49:55.748: E/AndroidRuntime(29256):    at android.util.Base64.encodeToString(Base64.java:456)
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
Kritias
  • 187
  • 1
  • 12
  • Logcat of crash and what is the size of the thumbnail array before crash. – Morrison Chang Jun 21 '15 at 18:10
  • 1
    Remember getThumbnail can return null: http://developer.android.com/reference/android/media/ExifInterface.html#getThumbnail() – Morrison Chang Jun 21 '15 at 18:15
  • I provided the Logcat but I can't give you the size of the thumbnail because I don't have the Nexus 5 right now, I will edit as soon as possible when I get it. – Kritias Jun 21 '15 at 18:16
  • @MorrisonChang I know but I don't understand why it could be null since it's not null on other phones and actually I don't want it to be null because my app can't run without it. – Kritias Jun 21 '15 at 18:20

1 Answers1

0

I certainly would not assume that all cameras will put a thumbnail in the EXIF headers. As Morrison Chang notes in the comments, getThumbnail() is allowed to return null. If it does, you will need to create your own thumbnail.

I don't understand why it could be null since it's not null on other phones

There are thousands of Android device models, and thousands of camera apps. I doubt that you have tested them all.

because my app can't run without it

Again, create your own thumbnail. A Google search on android create jpeg thumbnail turns up lots of possibilities, including:

Community
  • 1
  • 1
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491