Google Glass GDK CameraManager意图

时间:2014-02-20 21:59:52

标签: google-glass android-camera-intent google-gdk

有没有人知道当您使用GDK Cameramanager Intent拍照时,有没有办法不显示预览或自动关闭它?捕获图像以便在应用程序中使用,并且不想点击接受。

我可能错过了一些东西。

谢谢,

2 个答案:

答案 0 :(得分:1)

你可以试试这个:

      Intent localIntent = new Intent("com.google.glass.action.TAKE_PICTURE_FROM_SCREEN_OFF");
      localIntent.putExtra("should_finish_turn_screen_off", true);
      localIntent.putExtra("should_take_picture", true);
      localIntent.putExtra("screenshot_file_path", pathToFile);
      startActivity(localIntent);

几秒后它会自动关闭预览。

答案 1 :(得分:0)

试试这个......

private void takePicture() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent, 0);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 0 && resultCode == RESULT_OK) {
        String picturePath=data.getStringExtra(CameraManager.EXTRA_PICTURE_FILE_PATH);
        processPictureWhenReady(picturePath);
    }
    super.onActivityResult(requestCode, resultCode, data);
}

private void processPictureWhenReady(final String picturePath) {
    final File pictureFile = new File(picturePath);

    if (pictureFile.exists()) {

        // The picture is ready; process it.
        // Write your code here

    } else {

final File parentDirectory = pictureFile.getParentFile();
    FileObserver observer = new FileObserver(parentDirectory.getPath()) {
        // Protect against additional pending events after CLOSE_WRITE is
        // handled.
        private boolean isFileWritten;

        @Override
        public void onEvent(int event, String path) {
            if (!isFileWritten) {
                // For safety, make sure that the file that was created in
                // the directory is actually the one that we're expecting.
                File affectedFile = new File(parentDirectory, path);
                isFileWritten = (event == FileObserver.CLOSE_WRITE
                        && affectedFile.equals(pictureFile));

                if (isFileWritten) {
                    stopWatching();

                    // Now that the file is ready, recursively call
                    // processPictureWhenReady again (on the UI thread).
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            processPictureWhenReady(picturePath);
                        }
                    });
                }
            }
        }};
        observer.startWatching();
    }
}