2014-02-20 47 views
0

有誰知道如果您使用GDK Cameramanager Intent拍照時,有沒有辦法顯示預覽或自動關閉它?捕獲圖像以供在應用程序中使用,並且不希望必須點擊接受。Google Glass GDK CameraManager意圖

我可能錯過了一些東西。

感謝,

回答

1

你可以試試這個:

 Intent localIntent = new Intent("com.google.glass.action.TAKE_PICTURE_FROM_SCREEN_OFF"); 
     localIntent.putExtra("should_finish_turn_screen_off", true); 
     localIntent.putExtra("should_take_picture", true); 
     localIntent.putExtra("screenshot_file_path", pathToFile); 
     startActivity(localIntent); 

它會在幾秒後自動關閉預覽。

+0

哪裏是每個意圖採取控制等方面的弦參考? – ErstwhileIII

+0

我從GlassHome.apk得到了這段代碼 – Aenterhy

0

試試這個...

private void takePicture() { 
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    startActivityForResult(intent, 0); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == 0 && resultCode == RESULT_OK) { 
     String picturePath=data.getStringExtra(CameraManager.EXTRA_PICTURE_FILE_PATH); 
     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. 
     // Write your code here 

    } else { 

final File parentDirectory = pictureFile.getParentFile(); 
    FileObserver observer = new FileObserver(parentDirectory.getPath()) { 
     // Protect against additional pending events after CLOSE_WRITE 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 = (event == FileObserver.CLOSE_WRITE 
         && 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(); 
    } 
}