我无法捕获图像并将其保存到Google Glass上的外部存储空间。我有以下代码。
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null);
String imagePath = getPhotoPath();
_imagePath = imagePath;
File imageFile = new File(_imagePath);
Uri imageUri = Uri.fromFile(imageFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(cameraIntent, ACTION_CAPTURE_IMAGE);
getPhotoPath()的代码
private String getPhotoPath(){
String photoPath = null;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
long captureTime = System.currentTimeMillis();
photoPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/TOTAL_" + captureTime + ".jpg";
}
return photoPath;
}
我已经验证_imagePath不是null但是当我尝试在onActivityResult()中执行以下操作时
File imageFile = new File(_imagePath);
if(!imageFile.exists()){
Log.d(LOG_TAG, "sendPhoto: FILE DOES NOT EXIST, imagePath=" + _imagePath);
}
该文件不存在。我可以通过查看Eclipse中Google Glass设备的文件资源管理器来验证它是否存在于存储中。
我在项目的清单中有WRITE_EXTERNAL_STORAGE权限,但仍有一些问题。
可能相关的logcat消息:
01-06 16:28:15.067: E/CachedFilesManager(634): Failed to change mode on file /mnt/sdcard/thumbnail_cache/t_thumb_20140106_162814_113.jpg
01-06 16:28:15.067: E/CachedFilesManager(634): java.io.IOException: Operation not permitted
01-06 16:28:15.067: E/CachedFilesManager(634): at com.google.glass.fs.Filesystem.changeMode(Native Method)
01-06 16:28:15.067: E/CachedFilesManager(634): at com.google.glass.util.CachedFilesManager.save(CachedFilesManager.java:433)
01-06 16:28:15.067: E/CachedFilesManager(634): at com.google.glass.camera.CameraUtils.saveThumbnailToCachedFiles(CameraUtils.java:76)
01-06 16:28:15.067: E/CachedFilesManager(634): at com.google.glass.camera.ApiTakePictureActivity$1.doInBackground(ApiTakePictureActivity.java:110)
01-06 16:28:15.067: E/CachedFilesManager(634): at com.google.glass.camera.ApiTakePictureActivity$1.doInBackground(ApiTakePictureActivity.java:105)
01-06 16:28:15.067: E/CachedFilesManager(634): at android.os.AsyncTask$2.call(AsyncTask.java:273)
01-06 16:28:15.067: E/CachedFilesManager(634): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-06 16:28:15.067: E/CachedFilesManager(634): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-06 16:28:15.067: E/CachedFilesManager(634): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-06 16:28:15.067: E/CachedFilesManager(634): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-06 16:28:15.067: E/CachedFilesManager(634): at java.lang.Thread.run(Thread.java:856)
知道发生了什么事吗?写入Glass存储是不允许的?似乎不太可能,但我不知道发生了什么。
答案 0 :(得分:3)
Glass不支持EXTRA_OUTPUT
intent额外指定最终图像文件的路径。相反,请参阅GDK Camera Developer Guide中的示例,了解如何检索已保存图像文件的路径,并使用FileObserver
等待将其写出。