0

Is it possible at all to react to the Xperia Z3's hardware camera button? I've tried android.intent.action.CAMERA_BUTTON:

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:screenOrientation="landscape">
    <intent-filter android:priority="1000">
        <action android:name="android.intent.action.CAMERA_BUTTON" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

But still the built-in camera app is opened.

Looking into the Logcat, the button does indeed not fire a CAMERA_BUTTON intent but the specific one for the vendor app. Did anyone succeed with outsmarting the device?

PhilLab
  • 4,777
  • 1
  • 25
  • 77
  • As a user, you might poke through Settings and see if there's an option to control what app is started via the `CAMERA` button. – CommonsWare May 24 '15 at 11:56
  • Nice. I did not think about that :-) but well, this is tricky because I would have to make my users doing that. Apart from that, a quick search did not reveal any such setting – PhilLab May 24 '15 at 11:59

2 Answers2

0

Could you not use onKeyDown instead? This is working on my Z3:

 @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_CAMERA) {
            //do something
            return true;
        } 
        return true;
    }
Pete
  • 597
  • 1
  • 8
  • 27
  • Well, I haven't tried that. Is this also possible for an intent, e.g. when my app is not yet opened? – PhilLab Jun 02 '15 at 12:17
  • @PhilLab Ah I see, no probably not, unless you have a service running which catches the button press, but even then the system settings might override it. – Pete Jun 02 '15 at 20:18
0

Your code is good, but the default camera is eating up the broadcast for me as well. The only solution Ive found was going into the the device Settings -> Apps -> Camera -> Disable. (so not just disabling Quick launch, but disabling the whole app). I receive the broadcasts properly after that.

tibbi
  • 249
  • 4
  • 27