0

所以我在下面使用的代码片段。每次我调用意图时,它都会拍照,我可以看到照片成功保存,因为我在我的 Mac 上打开了图像捕获。除了有一个问题......它使用与我给它的文件名完全不同的文件名保存它。从返回的意图中的数据startActivityForResult也返回 null。有没有其他人遇到过这个问题,因为我的代码完全符合它应该的样子,我什至将它修复为工作/看起来更像使用相机意图逻辑的文档版本。

代码:

    //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();
4

1 回答 1

4

Glass 相机不支持将EXTRA_OUTPUTURI 作为 Activity 的输入。相反,您应该使用EXTRA_PICTURE_FILE_PATHextra from CameraManagerinside检索图像路径onActivityResult

于 2013-12-18T02:21:57.930 回答