Question

Does anyone know if when you use the GDK Cameramanager Intent to take a picture, is there a way to not show the preview or close it automatically? Capturing an image for use in app and don't want to have to tap to accept.

I probably have missed something.

Thanks,

No correct solution

OTHER TIPS

You can try this:

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

It will close your preview automatically after few seconds.

try this...

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();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top