gpt4 book ai didi

android - 无法访问在 Google Glass 上的应用内拍摄的照片

转载 作者:行者123 更新时间:2023-11-29 20:59:10 25 4
gpt4 key购买 nike

我对 Google Glass 开发感到困惑!我的应用目前正在使用内置相机功能和 GDK 站点 (https://developers.google.com/glass/develop/gdk/camera) 上的示例代码拍照。当我拍照时,看起来像是正在拍照,但是当我尝试将它上传到 imgur 服务器(使用他们的 API)时,我得到一个 FileNotFound 异常。此外,当我尝试使用 Android Studio 的文件资源管理器时,我似乎无法在它应该位于的文件路径中找到任何图像。似乎文件没有被创建,或者我以某种方式访问​​了错误的路径。我可能做错了什么?

使用相机的代码:

    public void startRecog(){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(TAG,"Got to onActivity");
Log.i(TAG,"Request code: " + requestCode + ", Result code: " + resultCode + ", what it wants: " + RESULT_OK);
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) {
Log.i(TAG,"Got inside the IF");
String picturePath = data.getStringExtra(Intents.EXTRA_THUMBNAIL_FILE_PATH);
// String picturePath = data.getStringExtra(Intents.EXTRA_PICTURE_FILE_PATH);

Log.i(TAG,"The real path: " + picturePath);
processPictureWhenReady(picturePath);
}

super.onActivityResult(requestCode, resultCode, data);
}

private void processPictureWhenReady(final String picturePath) {
final File pictureFile = new File(picturePath);

if (pictureFile.exists()) {
// The picture is ready; process it.
Log.i(TAG,"Got in from the picture processing");
new ImgurUploadTask(Uri.parse(picturePath), this).execute();
} else {
// The file does not exist yet. Before starting the file observer, you
// can update your UI to let the user know that the application is
// waiting for the picture (for example, by displaying the thumbnail
// image and a progress indicator).

final File parentDirectory = pictureFile.getParentFile();
FileObserver observer = new FileObserver(parentDirectory.getPath(),
FileObserver.CLOSE_WRITE | FileObserver.MOVED_TO) {
// Protect against additional pending events after CLOSE_WRITE
// or MOVED_TO is handled.
private boolean isFileWritten;

@Override
public void onEvent(int event, String path) {
if (!isFileWritten) {
// For safety, make sure that the file that was created in
// the directory is actually the one that we're expecting.
File affectedFile = new File(parentDirectory, path);
isFileWritten = affectedFile.equals(pictureFile);

if (isFileWritten) {
stopWatching();

// Now that the file is ready, recursively call
// processPictureWhenReady again (on the UI thread).
runOnUiThread(new Runnable() {
@Override
public void run() {
processPictureWhenReady(picturePath);
}
});
}
}
}
};
observer.startWatching();
}
}

我得到的错误:

11-01 14:34:43.281  10449-10449/com.example.cerveau.recognizeplaces I/RecogPlaces﹕ Got to onActivity
11-01 14:34:43.281 10449-10449/com.example.cerveau.recognizeplaces I/RecogPlaces﹕ Request code: 100, Result code: -1, what it wants: -1
11-01 14:34:43.281 10449-10449/com.example.cerveau.recognizeplaces I/RecogPlaces﹕ Got inside the IF
11-01 14:34:43.281 10449-10449/com.example.cerveau.recognizeplaces I/RecogPlaces﹕ The real path: /storage/emulated/0/storage/emulated/0/thumbnail_cache/t_thumb_20141101_143439_397.jpg
11-01 14:34:43.281 10449-10449/com.example.cerveau.recognizeplaces I/RecogPlaces﹕ Got in from the picture processing
11-01 14:34:43.288 10449-10704/com.example.cerveau.recognizeplaces E/ImgurUploadTask﹕ could not open InputStream
java.io.FileNotFoundException: No content provider: /storage/emulated/0/thumbnail_cache/t_thumb_20141101_143439_397.jpg
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1049)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:904)
at android.content.ContentResolver.openInputStream(ContentResolver.java:629)
at com.example.cerveau.recognizeplaces.ImgurUploadTask.doInBackground(ImgurUploadTask.java:32)
at com.example.cerveau.recognizeplaces.ImgurUploadTask.doInBackground(ImgurUploadTask.java:16)
at android.os.AsyncTask$2.call(AsyncTask.java:302)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:240)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

是的,我认为我在我的 AndroidManifest 中设置了正确的权限...

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />

谢谢大家!在为 Glass 开发的每一步中,我都一直在努力解决问题,这让我无休止地感到沮丧。非常感谢您的帮助!

最佳答案

new ImgurUploadTask(Uri.parse(picturePath)

这是你的问题。您不能在存储路径(如“/storage/emulated/0/thumbnail_cache...”)上使用 Uri.parse,因为它不合格。

像这样创建 Uri:

Uri.fromFile(pictureFile)

这将输出一个以“file://”开头的有效 Uri。

关于android - 无法访问在 Google Glass 上的应用内拍摄的照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26691955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com