Question

I'm a newbie to android and i'm trying to make an app that respond to a hardware input like camera button, handsfree call answer button,etc.

For example take camera button. When it is pressed the default camera app is launched. What I want to do is prevent that default response and make my app respond to that. I know it is possible to replace the camera app but thats not what i expect.

When the button is pressed, my app should run first and my app will direct to the camera app once my app is done. If this is possible please point me in the right direction

Was it helpful?

Solution

At the present time, ACTION_CAMERA_BUTTON is an ordered broadcast. You can create an <intent-filter> with a higher priority to try to get control before the firmware's own camera app, do what you want to do, and call abortBroadcast() to prevent lower-priority filters from receiving this broadcast.

However:

  • You have no way to know at compile time what the priority is of the camera app in the firmware, or any other camera apps that the user may have installed.

  • ACTION_CAMERA_BUTTON is not documented as being an ordered broadcast. Hence, older versions of Android might not have it be ordered, future versions of Android might not have it be ordered, and device manufacturers do not necessarily have to keep it ordered.

  • Very few devices have a CAMERA button

OTHER TIPS

It is on purpose left to the user to decide what to do when you press for example press the camera button (if the phone has such a button, most don't!). By default it opens the camera app, but as it sounds you already know this and how to register an activity to also receive those events (intent).

This will leave the user to choose which app (or rather Activity) to use when that button is pressed. If the user wants to he can select your activity in the list that will now pop up (as there are now two choices of how ta handle the camera button press). He/she can also select to always use one of the choices in the list. So if your app is what the users wants he can select that, and if he/she always wants your app when the button is pressed he/she can specify that as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top