I have a simple GDK app that has a menu option on a LiveCard to take a photo. I've followed the instructions in the Documentation to use the FileObserver very similar to the example there. However, once the file is done writing, I attempt to call a method in the binder to my service which then in turn tries to set the image uri on an ImageView in a RemoteView.
In the AndroidManifest.xml I have the following permissions:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
MenuActivity:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.add_photo:
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE), TAKE_PIC_REQ);
break;
}
return super.onOptionsItemSelected(item);
}
...
private void processPictureWhenReady(final String picturePath) {
final File pictureFile = new File(picturePath);
if (pictureFile.exists()) {
liveCardService.setPicture(picturePath);
}
...
LiveCardService:
public class CompPlayerBinder extends Binder {
public void setPlayerPicture(String picturePath) {
liveCard.unpublish();
RemoteViews view = new RemoteViews(getPackageName(), R.layout.photo_layout);
view.setImageViewUri(R.id.the_photo, Uri.fromFile(new File(picturePath)));
liveCard.setViews(view);
Intent i = new Intent(CompPlayerService.this, MenuActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
liveCard.setAction(PendingIntent.getActivity(Service.this, 0, i, 0));
liveCard.publish(LiveCard.PublishMode.SILENT);
}
}
When I run this I'm able to take the photo, but when I tap to accept, I get the following exception in my log
02-13 22:25:53.750 576-3201/? E/CachedFilesManager﹕ Failed to change mode on file
/mnt/sdcard/thumbnail_cache/t_thumb_20140213_222552_748.jpg java.io.IOException: Operation not permitted at com.google.glass.fs.Filesystem.changeMode(Native Method) at com.google.glass.util.CachedFilesManager.save(CachedFilesManager.java:433) at com.google.glass.camera.CameraUtils.saveThumbnailToCachedFiles(CameraUtils.java:76) at com.google.glass.camera.ApiTakePictureActivity$1.doInBackground(ApiTakePictureActivity.java:110) at com.google.glass.camera.ApiTakePictureActivity$1.doInBackground(ApiTakePictureActivity.java:105) at android.os.AsyncTask$2.call(AsyncTask.java:273) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) at java.util.concurrent.FutureTask.run(FutureTask.java:137) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) at java.lang.Thread.run(Thread.java:856)