我有一個應用程序在Android中,我想爲相機的物理硬件按鈕被按下時拍照。我註冊了這種類型的動作的意圖,但我的廣播接收器永遠不會被調用。ACTION_CAMERA_BUTTON的廣播接收器永遠不會被調用
這是我如何做的:
protected void onResume() {
Log.e(TAG, "onResume");
super.onResume();
drb = new Adisor();
IntentFilter i = new IntentFilter(
"android.intent.action.CAMERA_BUTTON"
);
registerReceiver(drb, i);
}
在我的清單文件:擴展BroadcastReceiver
public class Adisor extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT) != null) {
// prevent the camera app from opening
abortBroadcast();
System.out.println("HEY");
mCamera.takePicture(null, mPictureCallback, mPictureCallback);
}
}
}
這裏就是我登記我的接收器,監聽行動
類我有這個:
<activity android:name=".TakePhoto" />
<receiver android:name=".Adisor" >
<intent-filter android:priority="10000">
<action android:name="android.intent.action.CAMERA_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
我正在做這一切的活動的名稱是:TakePhoto
。我的問題是爲什麼我的onReceive()
方法永遠不會被調用!
無論是這樣的:
System.out.println("HEY");
出現在我的logcat或方法
System.out.println("HEY");
mCamera.takePicture(null, mPictureCallbacmPictureCallback);
被調用! 我做錯了什麼?
,如果它進入,如果() – Blundell
我用的System.out嘗試之外的廣播接收你見過。 println()並沒有任何顯示.....我試過外部如果()...有什麼可能是錯的? – Gabrielle
請幫我也http://stackoverflow.com/questions/24989221/how-to-get-camera-click-event-with-the-help-of-broadcast-receiver –