2015-02-24 103 views
1

當攝像頭捕獲視頻時,是否有方法通過broadcast接收器(或任何其他方式)進行檢測。BroadCast Reciever檢測視頻是從攝像頭捕獲的

我一直在使用下面的代碼做了同樣的相機照片:

在清單:

<receiver 
      android:name=".CameraPhotoReceiver" 
      android:enabled="true" > 
      <intent-filter> 
       <action android:name="com.android.camera.NEW_PICTURE" /> 
       <action android:name="android.hardware.action.NEW_PICTURE" /> 

       <data android:mimeType="image/*" /> 
      </intent-filter> 
     </receiver> 

廣播接收器類:

public class CameraPhotoReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent arg1) 
{ 
    // TODO Auto-generated method stub 

    Cursor cursor = context.getContentResolver().query(arg1.getData(), null, null, null, null); 

    cursor.moveToFirst(); 

    String image_path = cursor.getString(cursor.getColumnIndex("_data")); 

    Toast.makeText(context, "New Photo is Saved as : " + image_path, Toast.LENGTH_SHORT).show(); 
} 

} 
  • 我想要陪伴plish是在從攝像頭捕獲新視頻時從廣播接收器onReceive上傳視頻。

  • 等待從您的經驗中學習。在此先感謝

  • 編輯:具體來說,我要做到這一點只有從相機捕獲的視頻

+0

:剛剛嘗試對清單中的相機按鈕CLIK事件和檢查廣播接收器類的輸出,該輸出圖像或video..if它是視頻,然後執行上傳到服務器的動作。 – 2015-02-24 12:06:04

+0

@BornToWin plz一行或兩行代碼可以解決我的問題 – 2015-02-24 12:09:46

+0

:我不明白你在說什麼? – 2015-02-24 12:12:33

回答

0

也許你可以使用媒體的URI ContentObserver作爲觸發,然後檢查的時間戳媒體商店中最新的視頻文件?

+0

感謝您的回覆,你能告訴我任何一個例子,我怎麼才能實現這個..或一些代碼 – 2015-02-24 11:38:23

0

你有這樣的清單聲明:

<receiver 
     android:name=".CameraEventReciver" 
     android:enabled="true" > 
     <intent-filter> 
      <action android:name="android.hardware.action.NEW_PICTURE" /> 
      <action android:name="android.hardware.action.NEW_VIDEO" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:mimeType="image/*" /> 
      <data android:mimeType="video/*" /> 
     </intent-filter> 
    </receiver>