0

So snippets of the code I am using below. Every time I call the intent, it takes the picture, and I can see the photo successfully save because I have the image capture open on my mac. Except theres a problem... it saves it with a completely different file name than what I gave it. The data from the intent returned from startActivityForResult also returns null. Has anyone else had this problem because my code is exactly as it should be and I even fixed it up to work/look more like the docs version of using the camera intent logic.

Code:

    //Calling the intent
    Uri outputFileUri = Uri.fromFile(createdMediaFile);
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);       
    startActivityForResult(cameraIntent, RUN_CAMERA);

    //onActivityResult()
            File mediaStorageDir = new File(
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), appPhotoDirName
                    );
            File photo = new File(mediaStorageDir.getPath() + File.separator +
                    "IMG_"+ timeStamp + ".jpg");
            Log.d(TAG, photo.getAbsolutePath());
            Log.d(TAG, "Does file exists: "+photo.exists());
            observer = new FileObserver(photo.getAbsolutePath()) { 
                // set up a file observer to watch this directory on sd card
                 @Override
                 public void onEvent(int event, String file) {
                     Log.d(TAG, "File created [" + file + "]");

                 }
             };
             observer.startWatching();
Tony Allevato
  • 6,369
  • 1
  • 27
  • 33
Andy
  • 9,963
  • 19
  • 71
  • 123

1 Answers1

4

The Glass camera does not support the EXTRA_OUTPUT URI as an input into the activity. Instead, you should retrieve the image path using the EXTRA_PICTURE_FILE_PATH extra from CameraManager inside onActivityResult.

Tony Allevato
  • 6,369
  • 1
  • 27
  • 33
  • Thanks a lot for the help :) – Andy Dec 18 '13 at 02:40
  • Actually I am still a but confused. How do I access `CameraManager`? – Andy Dec 18 '13 at 02:50
  • Make sure you've updated your GDK to XE12 through the Android SDK Manager and then you can import the `com.google.android.glass.media.CameraManager` class, which contains the intent extra constant you need. – Tony Allevato Dec 18 '13 at 03:02
  • Btw, incase you guys didn't already know, the `Camera` doc is down: https://developers.google.com/glass/develop/gdk/reference/android/hardware/Camera – Andy Dec 18 '13 at 03:05
  • Well thanks for getting me this far. But the `FileObserver` is never running onEvent when its found. How long does it take for the image to be ready because I see it pop up on my macs image capture almost immediately. – Andy Dec 18 '13 at 03:24
  • The `Camera` class was removed in XE12 and the constants were moved into `CameraManager`. Regarding the `FileObserver`, make sure that you observe the *parent directory* of the file path that you get from `EXTRA_PICTURE_FILE_PATH` and handle a `CLOSE_WRITE` event that matches that file. – Tony Allevato Dec 18 '13 at 04:15