无法访问Google Glass上的应用拍摄的照片

问题描述:

我在这里与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开发的每一步都陷入困境,这让我感到无法接受。我非常感谢你的帮助!

new ImgurUploadTask(Uri.parse(picturePath) 

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

Uri.fromFile(pictureFile) 

这将输出一个有效的URI开头:

这样创建的URI。