Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sendUserActionEvent() mView==null on Samsung Tab3

I am trying to preview an image after capturing it using camera from inside my app, I am sure the path is not null but I am receiving this error in this line of code Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),options); and there is no image view. Note: I tested the code on another device (not Samsung) and it works.

like image 228
user3524254 Avatar asked Apr 11 '14 15:04

user3524254


2 Answers

I found a fix for this problem. Unfortunately, on some Samsung devices there is a problem with the built-in camera app that it causes screen rotation which leads to restarting your activity. For that mView becomes null. This happens also with other intents in samsung, not only in the camera. To fix it, you have to add this line in your manifest under your activity:

android:configChanges="orientation|screenSize"

Google mentions in the documentation

Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must declare android:configChanges="orientation|screenSize". However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).

like image 66
A.J Avatar answered Nov 07 '22 05:11

A.J


I have struggled with this error for days, this happens because Samsung Camera app is by default in Landscape mode.

If you start camera app from an activity in Portrait mode, when it comes back from Landscape it calls automatically again OnCreate, that's why your path is null.

I solved this by adding a static counter into the activity if it is equal to 0 app call oncreate and did it all, if it is greater than 0 loads only layout.

like image 3
lukaspp Avatar answered Nov 07 '22 07:11

lukaspp