0

Background:

I have a google glass, and I am thinking on an app that can grab any/all images a user takes using the native camera, and passing those images to an online service (e.g. Twitter or Google+). Kind of like a life-blogging style application.

In my first prototype, I implemented a FileObserver Service that watches for new files in the directory that glass stores its camera preview thumbnails (sdcard/google_cached_files/). The preview files always started with t_, so once I saw a new file there, I uploaded it to my webservice. This was working very well, but in Glass XE11 this cache file was moved out of my reach (/data/private-cache).

So now, I am watching the folder sdcard/DCIM/Camera/ for new .jpg files. This works ok, but the camera is storing the full size image there, so I have to wait 5-8 sec before the image is available for upload.

The Question:

Should it be possible to have background service running on glass that can intercept the camera event, and grab the thumbnail or the full image as a byte array from the Bundle so that I don't have to wait for it to write to disk before accessing it?

I have been reading up more on android development, and I suspect the answer involves implementing a BroadcastReciever in my service, but I wanted to check with the experts before going down the wrong path.

Many thanks in advance

Richie

1 Answers1

1

Yes. Implement a PreviewCallback. Same way it worked for phones, example here: http://www.dynamsoft.com/blog/webcam/how-to-implement-a-simple-barcode-scan-application-on-android/

I tested it on Google Glass and it works. In this post ( http://datawillconfess.blogspot.com.es/2013/11/google-glass-gdk.html ) I list the parameters (below the video) which the camera returns after doing:

     Camera m_camera = Camera.open(0);
     m_params = m_camera.getParameters();
     m_params.setPreviewFormat(ImageFormat.NV21);
     m_camera.setParameters(m_params);

     m_params = m_camera.getParameters();
     m_params.setPreviewSize(320,240);

     m_params.set("focus-mode",(String)"infinity");
     m_params.set("autofocus", "false");

     m_params.set("whitebalance",(String)"daylight");
     m_params.set("auto-whitebalance-lock",(String)"true");

     m_camera.setParameters(m_params);

     String s = m_params.flatten();
     Log.i("CAMERA PARAMETERS", "="+s);
  • Did you guys opt for using the Android Camera API instead of the Glass API? I tried using the startActivityForResult/onActivityResult method today and it did not work. The camera took a picture, and returned a file name in /mnt/sdcard/DCIM/Camera but here's the weird thing - after the camera has returned to my Activity that file doesn't exist. I tried checking for file existence, and I implemented a FileObserver, but the FileObserver never detected the file, after waiting a long time. But... when I launch the app again and look for that file, it is there! – Darren Nov 24 '13 at 06:17
  • 1
    Okay, figured this out after much head scratching. It's just that the image file created by the camera takes a long time to appear in the file system, like 8 seconds or more! A FileObserver didn't help either. I coded up a rather clunky timer and lo and behold it found the image but only after at least 8 seconds had passed. – Darren Nov 24 '13 at 06:57