1. 程式人生 > >Android監聽使用者開啟系統相機進行錄影行為

Android監聽使用者開啟系統相機進行錄影行為

首先,新建一個廣播:

public class CameraReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        T.log("監聽到了攝像完畢的廣播");
        Cursor cursor = context.getContentResolver().query(intent.getData(),
                null, null, null, null);
        cursor.moveToFirst();
        String path = cursor.getString(cursor.getColumnIndex("_data"
)); String name=context.getString(cursor.getColumnIndex("_display_name")); T.log("path:"+path+" name:"+name); } }

然後在manifest註冊:

  <receiver
            android:name=".receiver.CameraReceiver"
            android:enabled="true" >
            <intent-filter android:priority
="2147483647" >
<action android:name="com.android.camera.NEW_VIDEO" /> <action android:name="android.hardware.action.NEW_VIDEO" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="*/*"
/>
</intent-filter> </receiver>