简体   繁体   中英

Google glass GDK - Error opening camera

I'm developing an app for Glass using GDK but I'm having problems starting the camera intent

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, RESULT_FROM_CAMERA);

And the error is:

11-24 19:21:30.925: E/StrictMode(591): class com.google.glass.camera.ApiTakePictureActivity; instances=2; limit=1
11-24 19:21:30.925: E/StrictMode(591): android.os.StrictMode$InstanceCountViolation: class com.google.glass.camera.ApiTakePictureActivity; instances=2; limit=1
11-24 19:21:30.925: E/StrictMode(591):  at android.os.StrictMode.setClassInstanceLimit(StrictMode.java:1)

Any suggestion?

I think you need to use the constant from android.provider.MediaStore when creating your Intent:

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, RESULT_FROM_CAMERA);

Finally I've solved this. The Exception is still shown, but it works perfect. Using the extra "output" doesn't work since it is not used by the camera intent. OnActivityResult doesn't work either since it is not being called... What I've done is to ignore onActivityResult and to use a FileObserver pointing the Camera folder and waiting for an event when a new file is created.

final File photoFolder=new File(Environment.getExternalStorageDirectory() + File.separator + "DCIM/Camera");
fileObserver = new FileObserver(photoFolder.getAbsolutePath(), FileObserver.CREATE) 
        {
            @Override
            public void onEvent(int event, final String path) 
            {
                if(event == FileObserver.CREATE)
                {
                    fileObserver.stopWatching();
                    // Do whatever
                }
            }
        };
        fileObserver.startWatching();

您似乎打开了多个实例

instances=2; limit=1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM