我在拍摄图像并将其保存到 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 不为空,但是当我尝试在 onActivityResult() 中执行以下操作时
File imageFile = new File(_imagePath);
if(!imageFile.exists()){
Log.d(LOG_TAG, "sendPhoto: FILE DOES NOT EXIST, imagePath=" + _imagePath);
}
文件不存在。我可以通过查看 Eclipse 中 Google Glass 设备的文件资源管理器来验证它不存在于存储中。
我在项目的 list 中拥有 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 存储器?看起来不太可能,但我不知道发生了什么。
最佳答案
Glass 不支持用于指定最终图像文件路径的 EXTRA_OUTPUT
Intent extra。相反,请参阅 GDK Camera Developer Guide 中的示例查看如何检索保存的图像文件的路径并使用 FileObserver
等待它被写出。
关于android - 无法在 Google Glass 上拍摄图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20960776/