简体   繁体   English

Google glass 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 我正在使用GDK开发用于Glass的应用程序,但是在启动相机意图时遇到了问题

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时需要使用android.provider.MediaStore中的常量:

        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. OnActivityResult也不起作用,因为它没有被调用...我要做的是忽略onActivityResult并使用指向Camera文件夹的FileObserver并在创建新文件时等待事件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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