Search code examples
androidgoogle-glassgoogle-gdk

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?


Solution

  • 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();