谷歌眼镜GDK相机经理意图



>有谁知道当您使用 GDK 相机管理器意图拍照时,有没有办法不显示预览或自动关闭它? 捕获图像以在应用程序中使用,并且不想点击即可接受。

我可能错过了一些东西。

谢谢

你可以试试这个:

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

它将在几秒钟后自动关闭您的预览。

试试这个...

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

最新更新