我有一个应用程序在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 –