2011-10-31 66 views
5

Android Dev有一些簡單的代碼來描述如何通過Intents啓動攝像機。Android - 如何在調用攝像機意圖時自動錄製視頻

現在,如果您只是想啓動相機並等待用戶按下紅色的「REC」按鈕,那麼這很好。

但我想通過Intent調用攝像機,並告訴它以編程方式開始錄製。

我該怎麼做? 我是否在Intent命令中傳遞某種start()方法?

(如果它不能這樣做,請告訴我,可以設置爲自動錄製視頻一個簡單的代碼位 - 我一直在尋找的網站,但關於這個問題的所有codesnippets不工作)

private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100; 
private Uri fileUri; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 

// create Intent to take a picture and return control to the calling application 
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image 
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name 

// start the image capture Intent 
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); 
} 

回答

0

我已經找到了紮根設備上的解決方法。首先,用意向開始錄音(使用startActivity(),而不是startActivityForResult())。其次,用「輸入鍵事件27」發送CAMERA鍵碼。這是魔法!它開始錄製。錄音結束後,您可能應該按回(代碼4)。

整個鍵序列是:

  1. CAMERA:開始記錄(定時器出現在屏幕上)。在發送 意圖爲安全後,稍後發送了一下,
  2. DPAD_DOWNDPAD_RIGHT最後DPAD_CENTER被 需要驗證shootage!
  3. BACK返回到您的活動。
+0

你能告訴我如何發送輸入關鍵事件嗎? –

相關問題