尝试访问LiveCard服务中的活动拍摄的照片时出现IOException

时间:2014-02-14 06:30:06

标签: android camera google-glass ioexception google-gdk

我有一个简单的GDK应用程序,在LiveCard上有一个菜单选项来拍照。我按照文档中的说明使用FileObserver非常类似于那里的示例。但是,一旦文件完成写入,我会尝试将绑定器中的方法调用到我的服务,然后又尝试在RemoteView中的ImageView上设置图像uri。

在AndroidManifest.xml中,我拥有以下权限:


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




     }
    }

当我运行此功能时,我可以拍摄照片,但是当我点击接受时,我的日志中会出现以下异常

  

02-13 22:25:53.750 576-3201 /? E / CachedFilesManager:失败   更改文件上的模式

     

/mnt/sdcard/thumbnail_cache/t_thumb_20140213_222552_748.jpg       java.io.IOException:不允许操作               在com.google.glass.fs.Filesystem.changeMode(本机方法)               在com.google.glass.util.CachedFilesManager.save(CachedFilesManager.java:433)               在com.google.glass.camera.CameraUtils.saveThumbnailToCachedFiles(CameraUtils.java:76)               在com.google.glass.camera.ApiTakePictureActivity $ 1.doInBackground(ApiTakePictureActivity.java:110)               在com.google.glass.camera.ApiTakePictureActivity $ 1.doInBackground(ApiTakePictureActivity.java:105)               在android.os.AsyncTask $ 2.call(AsyncTask.java:273)               at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:305)               在java.util.concurrent.FutureTask.run(FutureTask.java:137)               在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)               at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:569)               在java.lang.Thread.run(Thread.java:856)

2 个答案:

答案 0 :(得分:1)

我目前正在使用活动中的内容解析程序来抓取最后拍摄的照片。 这是为活动编码的,因此您可能需要调整生活卡。

这里有一个脏项目 https://github.com/silenz357/Glass这是“工作”。希望它有所帮助

     String[] projection = new String[]{MediaStore.Images.ImageColumns._ID,MediaStore.Images.ImageColumns.DATA,MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,MediaStore.Images.ImageColumns.DATE_TAKEN,MediaStore.Images.ImageColumns.MIME_TYPE};                  
     final Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,projection, null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");                
    if(cursor != null){                 
         cursor.moveToFirst();
         String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA));                    t.setText(path);
         ImageView imageView = (ImageView)findViewById(R.id.imageView1);    
                  image = BitmapFactory.decodeFile(path);                   
         int nh = (int) ( image.getHeight() * (512.0 / image.getWidth()) );                                
         Bitmap scaled = Bitmap.createScaledBitmap(image, 512, nh, true);                       
         imageView.setImageBitmap(scaled);

答案 1 :(得分:0)

刚刚弄明白我的问题。我正在关注MenuActivity的Compass示例。在该示例中,关闭菜单后,活动结束,因此onActivityResult永远不会有机会运行。

@Override
public void onOptionsMenuClosed(Menu menu) {
    super.onOptionsMenuClosed(menu);

    unbindService(mConnection);

    // We must call finish() from this method to ensure that the activity ends either when an
    // item is selected from the menu or when the menu is dismissed by swiping down.
    finish();
}

所以我所做的只是关闭其他菜单选项的菜单活动,并让活动继续运行,直到照片完成处理完毕。