MysticMagicϡ
MysticMagicϡ

Reputation: 28823

Application is not receiving broadcast for camera being opened

I want to receive a broadcast for camera being opened. I want to block that process if some condition is true.

I am not getting broadcast for camera being opened. (I can get broadcast for new picture taken, which is not what I want.)

This is a piece of my manifest file:

<receiver
            android:name=".HardwareActionListener"
            android:enabled="true"
            android:exported="true" >
            <intent-filter android:priority="1000" >
                <action android:name="android.intent.action.CAMERA_BUTTON" >
                </action>
            </intent-filter>
</receiver>

This is a piece of my file HardwareActionListener.java

System.out.println("Intent action: " + intent.getAction());

if (intent.getAction().equalsIgnoreCase(
                "android.intent.action.CAMERA_BUTTON")) {
            System.out.println("CAMERA Button broadcast received and aborted");
            if(some_condition_true)
                  abortBroadcast();
        }

I have searched on google and stackverflow for this for a whole day. And I tried each and every combination. But I am not getting broadcast for camera being opened.

I am using Samsung Galaxy tab for testing. Which is not having hardware Camera button.

And one answer in this question says that

You can't: the intent is only generated by the hardware camera button, not by the button within a camera app.

So is there anything wrong in my manifest file's intent filter? Or is it the problem due to device not having hardware camera button?

Upvotes: 0

Views: 1097

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007644

I want to receive a broadcast for camera being opened.

There is no such broadcast.

I want to block that process if some condition is true.

Please use the device admin APIs to control access to the camera.

This is a piece of my manifest file

You are listening for CAMERA button presses, which may or may not have anything to do with a camera app, and do not exist on all devices.

But I am not getting broadcast for camera being opened.

That is because there is no such broadcast.

And one answer in this question says that "You can't: the intent is only generated by the hardware camera button, not by the button within a camera app."

That answer is correct.

Upvotes: 4

Related Questions