Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera crashing on Android 10 when launching intent

Tags:

android

I'm trying to add the ability to take a photo to my app which should be fairly simple however I'm running into issues on android 10 for some reason.

I followed the implementation details at https://developer.android.com/training/camera/photobasics (so far I've only implemented the basic functionality which should launch the camera app and return a bitmap of the thumbnail)

This all works on older emulated devices however when I test it on my physical Google Pixel and an emulated Pixel 2 (both running Android 10) I get a crash after calling startActivity:

btnCam.setOnClickListener(v -> {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }
});

The problem is, its not my app thats crashing but the camera app. If I look in logcat after the crash I get the following message:

2020-02-02 17:11:29.059 15592-15592/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.google.android.GoogleCamera, PID: 15592
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.GoogleCamera/com.google.android.apps.camera.legacy.app.activity.CaptureActivity}: java.lang.NullPointerException: Attempt to get length of null array
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.NullPointerException: Attempt to get length of null array
        at com.google.android.apps.camera.legacy.app.activity.CaptureActivity.onCreate(PG:12)
        at android.app.Activity.performCreate(Activity.java:7802)
        at android.app.Activity.performCreate(Activity.java:7791)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 

Logically given its crashing with java.lang.NullPointerException: Attempt to get length of null array I imagine its expecting some form of input that I'm not providing however I haven't found any mention of having to provide any extra parameters (I'm aware you can specify optional params to specify where to write the resulting photo to but nothing has said this is required)

Is anyone aware of this issue and how to resolve it on Android 10?

Thanks

like image 518
Darc Avatar asked Sep 02 '25 10:09

Darc


1 Answers

According to another post, this is a bug in the camera app which has recently been corrected. There is no need for your app to request permission to use the camera when you are using the camera app to take the photo.

But if you need your app to work on an API 29 emulator or device before the bug fix is pushed out, you can just add a <uses-permission> for any type of permission (even a fake one) to your AndroidManifest.xml:

<manifest ...>
   <uses-permission android:name="BLAH" />
   ...

</manifest>
like image 50
tronman Avatar answered Sep 04 '25 23:09

tronman