我在這裏與Google Glass開發混淆!我的應用程序正在使用GDK站點上的內置攝像頭功能和示例代碼拍攝照片(https://developers.google.com/glass/develop/gdk/camera)。當我拍照時,它看起來像是一張照片,但當我嘗試將它上傳到imgur服務器(使用他們的API)時,我得到一個FileNotFound異常。另外,當我嘗試使用Android Studio的文件資源管理器時,似乎無法在文件路徑中找到任何圖像。它看起來像文件沒有被創建,或者我以某種方式訪問錯誤的路徑。我可能做錯了什麼?無法訪問Google Glass上的應用拍攝的照片
代碼使用相機:
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開發的每一步都陷入困境,這讓我感到無法接受。我非常感謝你的幫助!