0

下面我使用的代碼片段。每次我打電話給這個意圖時,它都會拍攝照片,並且我可以成功保存照片,因爲我在我的Mac上打開了圖像捕獲功能。除了這個問題...它保存了一個完全不同於我給它的文件名。從startActivityForResult返回的意圖數據也返回null。有沒有其他人有這個問題,因爲我的代碼是完全一樣的,我甚至修復它的工作/看起來更像是使用相機意圖邏輯的文檔版本。使用GDK的Google Glass上的Camera Intent不會使用我提供的URI創建文件

代碼:

//Calling the intent 
    Uri outputFileUri = Uri.fromFile(createdMediaFile); 
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);  
    startActivityForResult(cameraIntent, RUN_CAMERA); 

    //onActivityResult() 
      File mediaStorageDir = new File(
        Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), appPhotoDirName 
        ); 
      File photo = new File(mediaStorageDir.getPath() + File.separator + 
        "IMG_"+ timeStamp + ".jpg"); 
      Log.d(TAG, photo.getAbsolutePath()); 
      Log.d(TAG, "Does file exists: "+photo.exists()); 
      observer = new FileObserver(photo.getAbsolutePath()) { 
       // set up a file observer to watch this directory on sd card 
       @Override 
       public void onEvent(int event, String file) { 
        Log.d(TAG, "File created [" + file + "]"); 

       } 
      }; 
      observer.startWatching(); 

回答

4

玻璃鏡頭不支持EXTRA_OUTPUT URI作爲輸入到活性。相反,您應該使用onActivityResult以內的CameraManager中的EXTRA_PICTURE_FILE_PATH額外部分檢索圖像路徑。

+0

非常感謝幫助:) – Andy

+0

其實我還是很困惑。我如何訪問'CameraManager'? – Andy

+0

確保您已通過Android SDK管理器將您的GDK更新爲XE12,然後您可以導入com.google.android.glass.media.CameraManager類,該類包含您需要的意圖額外常量。 –