Giter VIP home page Giter VIP logo

android-camera2basic's Introduction

Android Camera2Basic Sample

This repo has been migrated to github.com/android/camera. Please check that repo for future updates. Thank you!

android-camera2basic's People

Contributors

codingjeremy avatar ggfan avatar google-automerger avatar tjohns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-camera2basic's Issues

Lock camera timeout when requesting Camera permission

On 6.0 devices when I have camera permissions set everything works fine, but when I have to request the camera permission before using the camera and I click allow I get the following error:

`AndroidRuntime: FATAL EXCEPTION: main
Process: bla, PID: 22800
java.lang.RuntimeException: Unable to resume activity java.lang.RuntimeException: Time out waiting to lock camera opening.
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1388)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: Time out waiting to lock camera opening.
at ...SellCamera2Fragment.openCamera(SellCamera2Fragment.java:259)
at ...SellCamera2Fragment.onResume(SellCamera2Fragment.java:183)
at android.support.v4.app.Fragment.performResume(Fragment.java:2005)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1230)
at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:2052)
at android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:187)
at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:462)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:451)
at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:141)
at android.app.Activity.performResume(Activity.java:6336)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1388) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) ``

Bug: Only fires the flash and saves a picture once

Hi,

I've run into a problem where the Camara2Basic app will only save a picture the first time only when the flash fires. After successfully saving this first picture (with flash), the preview then becomes really dark and then won't save any more pictures.

The device I'm testing is a Nexus 6P with Android 6.0.1 (Jan 1st security patch).

I think I've found the cause of the issue. It seems to be related to resetting the AE precapture trigger after in unlockFocus(). I'm not sure if resetting AE precapture in unlockFocus() is the proper way to fix the problem, but I've attached my patch in case anyone is interested.

camera2basic_ae_trigger_reset.patch.txt

Taking snapshots while screen is off

Hi, this is not exactly an issue, since I don't know if this is a desired behavior.

I played a bit with the code and everything works great, the only thing I can't achieve is taking snapshots from the camera while the screen is off (imagine a smartphone working as a motion detector 24/7, I don't want to keep the screen on all the time).

When the screen is locked all the surface objects are dismissed and I can't find a way to keep taking timed snapshots.

Is there any advice on how to achieve this?
Thank you

Camera layout is skewed after being resumed from lock screen?

I changed this app to landscape orientation only.

And it works just fine if I press home and then open the app again, it resumes properly. But if I press the power button, then I turn my device on, and resume to the app, there is the error: "An error occurred while connecting to camera: 0", and the app just closes afterward.

So, I added android:configChanges with value "orientation|screenSize" and now the above error doesn't happen, but the screen layout is skewed.
screenshot
I don't understand, what is the difference between the two cases: pressing the power button off versue pressing the home button?

Source code "CameraCaptureSession.CaptureCallback CaptureCallback" camelCase

The variable starts with an uppercase letter "Capture".

Also of note: The comment for the method "This method should be called when we get a response in
* {@link #mCaptureCallback} from both {@link #lockFocus()}" seems incomplete. It implies "from both" in English language - but only lists a single item. As a tutorial/sample app, would be better to make sure that something isn't missing in this comment.

Thank you.

Nexus 5x captured image is inverted

When taking a picture using a Nexus 5x the picture is inverted (upside down)
I was looking for a fix regarding this issue here since it's Google sample :)

Crashes on devices without flash

On my Sony Xperia Z4 Tablet (which has no builtin flash on the backside) this demo crashes without any useful stacktrace whatsoever. After commenting out

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

in Camera2BasicFragment.java line 695 it works fine.

//EDIT:
also in

private void unlockFocus()

and

private void captureStillPicture()

Lacking privileges to access camera service

When using camera in landscape, closing screen and opening it, crashes the app. Tested on Nexus 5 with 6.0.1
FATAL EXCEPTION: main
Process: com.example.android.camera2basic, PID: 14591
java.lang.SecurityException: Lacking privileges to access camera service
at android.hardware.camera2.utils.CameraBinderDecorator.throwOnError(
CameraBinderDecorator.java:108)
at android.hardware.camera2.utils.CameraBinderDecorator$CameraBinderDecoratorListener.
onAfterInvocation(CameraBinderDecorator.java:73)
at android.hardware.camera2.utils.Decorator.invoke(Decorator.java:81)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at $Proxy1.cancelRequest(Unknown Source)
at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:926)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:378)
at android.hardware.camera2.impl.CameraCaptureSessionImpl$2.onDisconnected(CameraCaptureSessionImpl.java:514)
at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:228)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

How to open front camera

Hi, My application requirements is, I want to open front camera and take selfie. What should i do to open front camera. Is it possible?

The sample captures 2 images

Each invocation of takePicture captures 2 images. This can be verified by adding logging info to ImageSaver.run(). Issue seen on Motorola Nexus 6.

Face detection only work when ORIENTATION is Landscape

the Face detection works when I set the request mode: STATISTICS_FACE_DETECT_MODE_FULL
but the question is, face detection only work when I turn screen 90 degree.

How can I make it work when the screen is portrait which means rotate the original camera image for face detect. Thanks..

Needs update for Video Capture

Hi,
I am in the middle of build a camera app but this code does not show how to use the video functions of Camera2 yet Camera which I am able to find code and get video to work is deprecated. I think this should be updated to include video so developers can migrate faster.

Regards,
-J

Preview display skewed

Sometimes the preview presents a skewed image, as if you were elongating the image. Here's the most consistent way I can reproduce this:

  1. Start the app with phone in portrait mode. Preview may or may not be fine. If it is fine:
  2. Rotate the phone to landscape. Preview should stay fine.
  3. Rotate back to portrait. Now the preview should be weird and skewed.

I know that's a confusing description, hopefully you can reproduce it. I'm guessing it has to do with the configureTransform method?

Missing Manifest premissions entry to write to external storage location

Hi guys,

I just pulled the example after some time again from the repo (wanted to see about updates), imported the project into Android Studio, ran the app - but the pic.jpg didn't get stored.

06-19 13:18:58.165 25887-28705/com.example.android.camera2basic W/System.err﹕ java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.example.android.camera2basic/files/pic.jpg: open failed: EACCES (Permission denied)
06-19 13:18:58.165 25887-28705/com.example.android.camera2basic W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:456)
06-19 13:18:58.165 25887-28705/com.example.android.camera2basic W/System.err﹕ at java.io.FileOutputStream.(FileOutputStream.java:87)
06-19 13:18:58.165 25887-28705/com.example.android.camera2basic W/System.err﹕ at java.io.FileOutputStream.(FileOutputStream.java:72)
06-19 13:18:58.166 25887-28705/com.example.android.camera2basic W/System.err﹕ at com.example.android.camera2basic.Camera2BasicFragment$ImageSaver.run(Camera2BasicFragment.java:795)
06-19 13:18:58.166 25887-28705/com.example.android.camera2basic W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
06-19 13:18:58.166 25887-28705/com.example.android.camera2basic W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
06-19 13:18:58.166 25887-28705/com.example.android.camera2basic W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
06-19 13:18:58.166 25887-28705/com.example.android.camera2basic W/System.err﹕ at android.os.HandlerThread.run(HandlerThread.java:61)
06-19 13:18:58.166 25887-28705/com.example.android.camera2basic W/System.err﹕ Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
06-19 13:18:58.166 25887-28705/com.example.android.camera2basic W/System.err﹕ at libcore.io.Posix.open(Native Method)
06-19 13:18:58.166 25887-28705/com.example.android.camera2basic W/System.err﹕ at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
06-19 13:18:58.166 25887-28705/com.example.android.camera2basic W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:442)

obviously, the WRITE_EXTERNAL_STORAGE permission could get rid of the problem. The issue occurred on my NVIDIA Shield tablet, SDK version 22, with sdcard attached. Anybody else experiencing similar problems ?

Camera scaled on font camera of Nexus 7 2013

When I change the code for Front Camera

            if (characteristics.get(CameraCharacteristics.LENS_FACING)
                    == CameraCharacteristics.LENS_FACING_FRONT) {

// continue; // Coment here
// } // Coment here

..... do some thing here

////

Some time the display screen is scaled, some time it works. When I stop and resume application, it works perfect.

What's did I do wrong and how to fix it?

screen shot 2015-04-10 at 2 58 07 pm

App fails to open

E/AndroidRuntime( 5504): FATAL EXCEPTION: main
E/AndroidRuntime( 5504): Process: com.yohan.cameraexample, PID: 5504
E/AndroidRuntime( 5504): java.lang.RuntimeException: setParameters failed
E/AndroidRuntime( 5504): at android.hardware.Camera.native_setParameters(Native Method)
E/AndroidRuntime( 5504): at android.hardware.Camera.setParameters(Camera.java:1876)
E/AndroidRuntime( 5504): at com.yohan.cameraexample.Preview.surfaceChanged(Preview.java:77)
E/AndroidRuntime( 5504): at android.view.SurfaceView.updateWindow(SurfaceView.java:590)
E/AndroidRuntime( 5504): at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
E/AndroidRuntime( 5504): at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
E/AndroidRuntime( 5504): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1956)
E/AndroidRuntime( 5504): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
E/AndroidRuntime( 5504): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
E/AndroidRuntime( 5504): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
E/AndroidRuntime( 5504): at android.view.Choreographer.doCallbacks(Choreographer.java:580)
E/AndroidRuntime( 5504): at android.view.Choreographer.doFrame(Choreographer.java:550)
E/AndroidRuntime( 5504): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
E/AndroidRuntime( 5504): at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime( 5504): at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 5504): at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 5504): at android.app.ActivityThread.main(ActivityThread.java:5221)
E/AndroidRuntime( 5504): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5504): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 5504): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime( 5504): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Camera not re initialize second time in 5.1.1

Hi Team,

Here is my need is, to record a video in number of clips and i merge these clips by using some other third party tools.

For recording i used setMaxFileSize(<i set 10MB>). So the info listener called when recorder reaches 10MB, I used the below code.

@Override
    public void onInfo(MediaRecorder mr, int what, int extra) {

        Log.e("Max file size reached called what", what + "");
        switch (what) {
            case MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED:

              mMediaRecorder.reset();
// Here i store the clip in local storage and i start recording for getting the next part, why because once the max file size reached the recorder will be stopped.
                startRecordingVideo();
        }
    }

The above code is working fine in Android marshmallow, but when i test the same code in 5.1.1 i got the following error.

07-27 20:51:34.167 5810-12582/com.test.video E/CameraDeviceGLThread-0: Received exception on GL render thread: 
                                                                       java.lang.IllegalStateException: swapBuffers: EGL error: 0x300d
                                                                           at android.hardware.camera2.legacy.SurfaceTextureRenderer.checkEglError(SurfaceTextureRenderer.java:530)
                                                                           at android.hardware.camera2.legacy.SurfaceTextureRenderer.swapBuffers(SurfaceTextureRenderer.java:523)
                                                                           at android.hardware.camera2.legacy.SurfaceTextureRenderer.drawIntoSurfaces(SurfaceTextureRenderer.java:729)
                                                                           at android.hardware.camera2.legacy.GLThreadManager$1.handleMessage(GLThreadManager.java:105)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:98)
                                                                           at android.os.Looper.loop(Looper.java:211)
                                                                           at android.os.HandlerThread.run(HandlerThread.java:61)
07-27 20:51:34.167 5810-12582/com.test.video I/CameraDeviceState: Legacy camera service transitioning to state ERROR
07-27 20:51:34.275 5810-5810/com.test.video E/CameraCaptureSession: Session 1: Exception while stopping repeating: 
                                                                    android.hardware.camera2.CameraAccessException: The camera device has encountered a serious error
                                                                        at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:1478)
                                                                        at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:677)
                                                                        at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:328)
                                                                        at com.test.video.fragments.VideoContentRecording.closePreviewSession(VideoContentRecording.java:871)
                                                                        at com.test.video.fragments.VideoContentRecording.startRecordingVideo(VideoContentRecording.java:812)
                                                                        at com.test.video.fragments.VideoContentRecording.onInfo(VideoContentRecording.java:941)
                                                                        at android.media.MediaRecorder$EventHandler.handleMessage(MediaRecorder.java:1033)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:211)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5389)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at java.lang.reflect.Method.invoke(Method.java:372)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)

Guys, let me know how can i fix this, and please suggest if i'm on the right way or any other solution/possibilities to achieve my need. Thanks in advance.

how to pause preview?

Hi,
My question is: How to pause the preview( and draw some figures on the screen), and( touch a button to) resume previewing?

Thank you!

Face detection

How can i detec faces on the preview camera? Thanks in advance

Camera image upside down after orientation changes

If changing from one landscape orientation to the other very fast, such that it doesn't switch to portrait inbetween, the camera image is upside down afterwards. This is on a Nexus 4 updated to Android 5.1.

Lacking privileges to access camera service

                                                Process: com.example.android.camera2basic, PID: 14782
                                                                              java.lang.SecurityException: Lacking privileges to access camera service
                                                                                  at android.hardware.camera2.utils.CameraBinderDecorator.throwOnError(CameraBinderDecorator.java:108)
                                                                                  at android.hardware.camera2.legacy.CameraDeviceUserShim.connectBinderShim(CameraDeviceUserShim.java:331)
                                                                                  at android.hardware.camera2.CameraManager.openCameraDeviceUserAsync(CameraManager.java:267)
                                                                                  at android.hardware.camera2.CameraManager.openCamera(CameraManager.java:383)
                                                                                  at com.example.android.camera2basic.Camera2BasicFragment.openCamera(Camera2BasicFragment.java:616)
                                                                                  at com.example.android.camera2basic.Camera2BasicFragment.access$000(Camera2BasicFragment.java:74)
                                                                                  at com.example.android.camera2basic.Camera2BasicFragment$1.onSurfaceTextureAvailable(Camera2BasicFragment.java:140)

xiaomi 4c china 定制机的问题吗?

App crashes on image capture

Though this sample was designed for Android L developer preview, I downloaded the sample for Android L from http://developer.android.com/samples/Camera2Basic/. When I click the picture, I get following error

E/AndroidRuntimeFATAL EXCEPTION: CameraBackground
    Process: com.example.android.camera2basic, PID: 32593
    java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
            at com.example.android.camera2basic.Camera2BasicFragment$4.process(Camera2BasicFragment.java:269)
            at com.example.android.camera2basic.Camera2BasicFragment$4.onCaptureCompleted(Camera2BasicFragment.java:308)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at android.hardware.camera2.dispatch.InvokeDispatcher.dispatch(InvokeDispatcher.java:39)
            at android.hardware.camera2.dispatch.HandlerDispatcher$1.run(HandlerDispatcher.java:65)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.os.HandlerThread.run(HandlerThread.java:61)

My testing device is Nexus 4 and I am running Android L from this ROM http://forum.xda-developers.com/nexus-4/development/lpv-79-mako-port-beta-t2807446.
P.S. Native Camera App is running smoothly without any hiccups.

onCaptureCompleted have never been called

I tested this app on my Sony Xperia M2, API 22 and the method onCaptureCompleted have never been called.
I have fixed this issue with adding few else statement - see the end of this part of code:

  private void process(CaptureResult result) {
            switch (mState) {
                case STATE_PREVIEW: {
                    // We have nothing to do when the camera preview is working normally.
                    break;
                }
                case STATE_WAITING_LOCK: {
                    Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
                    if (afState == null) {
                        captureStillPicture();
                    } else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
                            CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
                        // CONTROL_AE_STATE can be null on some devices
                        Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
                        if (aeState == null ||
                                aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
                            mState = STATE_PICTURE_TAKEN;
                            captureStillPicture();
                        } else {
                            runPrecaptureSequence();
                        }
                    }

//ADDED BY ME
                    else {
                        captureStillPicture();
                    }

                    break;

What can be wrong?

Crashes if Google Camera is not installed

Logs:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.voicecamera/com.example.android.voicecamera.CameraActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.google.android.GoogleCamera bnds=[449,1604][665,1820](has extras) }

Fix: One needs to download and install the Google Camera apk from here http://www.apkmirror.com/apk/google-inc/camera/

UI thread blocks

The UI blocks when a picture is taken, but with the HandlerThread, it should be performing the write in the background.

Null pointer exception

I have just imported it in android studio using Import An android code samples

and after gradle build completed i run the app and getting this null pointer exception.

please help

07-28 04:55:24.705 6699-6699/com.example.android.camera2basic E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.camera2basic, PID: 6699
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.camera2.CaptureRequest$Builder.set(android.hardware.camera2.CaptureRequest$Key, java.lang.Object)' on a null object reference
at com.example.android.camera2basic.Camera2BasicFragment.lockFocus(Camera2BasicFragment.java:778)
at com.example.android.camera2basic.Camera2BasicFragment.takePicture(Camera2BasicFragment.java:769)
at com.example.android.camera2basic.Camera2BasicFragment.onClick(Camera2BasicFragment.java:890)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21153)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-28 04:57:47.686 7667-7667/com.example.android.camera2basic E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.camera2basic, PID: 7667
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.camera2.CaptureRequest$Builder.set(android.hardware.camera2.CaptureRequest$Key, java.lang.Object)' on a null object reference
at com.example.android.camera2basic.Camera2BasicFragment.lockFocus(Camera2BasicFragment.java:777)
at com.example.android.camera2basic.Camera2BasicFragment.takePicture(Camera2BasicFragment.java:768)
at com.example.android.camera2basic.Camera2BasicFragment.onClick(Camera2BasicFragment.java:889)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21153)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Permission

Camera2BasicFragment.java:514 "getActivity().checkSelfPermission(Manifest.permission.CAMERA)" call requires API level 23 but the current min set is 21. I'm testing in my phone that has API level 21 installed, what is the workaround or maybe deprecated version of 'checkSelfPermission'? Thank you very much.

"BufferQueue has been abandoned" Errors in LogCat

To reproduce this, run the app (tested on Nexus 7 2013 running Android 5.1), then press the BACK button to exit the app. Lines like the following will appear in LogCat:

05-07 16:02:31.527  14879-14895/com.example.android.camera2basic E/BufferQueueProducer﹕ [unnamed-14879-2] queueBuffer: BufferQueue has been abandoned
05-07 16:02:31.595  14879-14992/com.example.android.camera2basic E/BufferQueueProducer﹕ [unnamed-14879-2] queueBuffer: BufferQueue has been abandoned
05-07 16:02:31.661  14879-14896/com.example.android.camera2basic E/BufferQueueProducer﹕ [unnamed-14879-2] queueBuffer: BufferQueue has been abandoned
05-07 16:02:31.728  14879-14895/com.example.android.camera2basic E/BufferQueueProducer﹕ [unnamed-14879-2] queueBuffer: BufferQueue has been abandoned
05-07 16:02:31.796  14879-14992/com.example.android.camera2basic E/BufferQueueProducer﹕ [unnamed-14879-2] queueBuffer: BufferQueue has been abandoned

Based on some experiments, it appears that these messages come about after the CameraDevice is closed in closeCamera().

Do you know how we can get rid of those messages?

Thanks!

Focus Areas

I am trying to implement a camera with a focus on a special area.
So far I Have implemented a method from what I have seen in the tutorial

   private void setFocusArea()
         {

        MeteringRectangle[] focusAreas = new MeteringRectangle[1];

        Rect sensor_rect = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
        Rect focusArea = new Rect(
                0,
                0,
                sensor_rect.width()-1,
                (int)(sensor_rect.height()*0.5));
        focusAreas[0] = new MeteringRectangle(focusArea,MeteringRectangle.METERING_WEIGHT_MAX);

        if(mCameraCharacteristics!= null
                && mCameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF)>0)
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_REGIONS,focusAreas);

//        if(mCameraCharacteristics!= null
//                && mCameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE)>0)
//            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS,focusAreas);



    }

And I am calling this function right before every mPreviewRequestBuilder.build()

So it is supposed to focus on the top 50% of the image, but it just doesn't.

Any ideas, feedback, or where should I look ?

Be Stuck with two problems: ClassNotFoundException and hardware acceleration is not enabled.

Hi everyone:

I'm new comer for Android application development.
Just let somebody know if they are stuck in two issues:

I. AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.camera2basic.CameraActivity" on path: DexPathList[[zip file "/data/app/com.example.android.camera2basic-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

I move source codes location from

.\android-Camera2Basic-master\Application\src\main\java\com\example\android\camera2basic

to
.\android-Camera2Basic-master\Application\src\main\src\com\example\android\camera2basic

Then solve the first problem.

II. TextureView: A TextureView or a subclass can only be used with hardware acceleration enabled.

I add below settings into AndroidManifest.xml to resolve the error.

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

<application android:allowBackup="true"
    android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:theme="@style/MaterialTheme"
    android:hardwareAccelerated="true">

Now I can test the camera API 2 with this application. It's really helpful. Thanks.

BR.

Preview freezes With AddTarget

Hi, I want to get live stream from the camera. For this purpose I am adding
mPreviewBuilder.addTarget(mImageReader.getSurface) line of code in Camera2Basic example just after the first Target. After Adding the second target. It Freezes the camera view and doesn't go to call back onImageAvailable(ImageReader reader) after three images. What I am doing wrong I couldn't figure out. How can I get video stream frame like Camera One setOnPreviewCallback.

Face detection

How can i detec faces on the preview camera? Thanks in advance

Front Camera

Hi.
When I'm using front camera it dose not take a picture and log shows this:

 W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
 W/LegacyMetadataMapper: convertAfModeToLegacy - ignoring unsupported mode 4, defaulting to fixed
 W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
 W/LegacyMetadataMapper: convertAfModeToLegacy - ignoring unsupported mode 4, defaulting to fixed

I have this problem with Samsung Galaxy Note 4, But on Samsung Galaxy S4 everything are well;
Both have android 6 (Marshmallow).

Does not work on Nexus 9

  1. In portrait mode, the blue side bar and 'picture' button aren't visible due to the 4x3 aspect ratio of the Nexus 9. The blue bar should be semi-transparent like in the native app and overlaid on the camera preview if their bounds overlap.
  2. Tapping 'picture' cause the app to get stuck in the 'STATE_AWAITING_LOCK' state. I haven't found a way to capture a picture on a Nexus 9 using this sample app.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.