简体   繁体   English

使用GDK的Google Glass上的相机意图未使用我提供的URI创建文件

[英]Camera Intent on Google Glass using the GDK not creating the file with the URI I provide

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. 每次我调用意图时,它都会拍照,并且可以成功保存照片,因为在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. startActivityForResult返回的意图数据也返回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();

The Glass camera does not support the EXTRA_OUTPUT URI as an input into the activity. Glass相机不支持EXTRA_OUTPUT URI作为活动的输入。 Instead, you should retrieve the image path using the EXTRA_PICTURE_FILE_PATH extra from CameraManager inside onActivityResult . 相反,您应该使用onActivityResult内部的CameraManagerEXTRA_PICTURE_FILE_PATH来检索图像路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM