0

I have a problem with my BroadcastReceiver. It's not working. I couldn't find any satisfying answers for my problem. This is my code fragments:

    <receiver 
        android:name=".CameraReceiver" 
        android:enabled="true">
        <intent-filter>
            <action android:name="android.intent.action.CAMERA_BUTTON" />
        </intent-filter>
    </receiver>

@Override
public void onReceive(Context context, Intent intent) {     
    Toast.makeText(context, "It's working!", Toast.LENGTH_LONG).show();
}

I tried, following some suggestions I've found in the internet, to add something like this:

    <intent-filter android:priority="100000">

And so on, nevertheless there was no effect.

When I change android.intent.action.CAMERA_BUTTON to anything else, and do this action (for example android.net.wifi.WIFI_STATE_CHANGED), there always appears a Toast "It's working". But not when I use android.intent.action.CAMERA_BUTTON and take a photo. I don't know what's going on.

Any suggestions? I use Android emulator 2.2 and 2.3.3.

Grzes
  • 971
  • 1
  • 13
  • 28

3 Answers3

1

I am the author of that tutorial & patch for enabling the camera button on the emulator. The latest builds of the emulator do have support for the camera button because they merged my patch into the code base. However, for reasons that escape my understanding, they didn't merge the patch that updates the skins, so the first patch is useless. You need to make sure your skin has support for the camera button, as explained on my tutorial.

Also, I solved that because I wanted to test what you are also trying to test. My AndroidManifest.xml has a receiver section like yours, but I also have an intent-filter section inside the <activity> which is meant to receive the intent:

<intent-filter>
    <action android:name="android.media.action.STILL_IMAGE_CAMERA" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
sole
  • 2,057
  • 2
  • 17
  • 18
0

Add <category android:name="android.intent.category.DEFAULT" /> to your intent filter, as mentioned here.

Community
  • 1
  • 1
Femi
  • 64,273
  • 8
  • 118
  • 148
  • Still not working... Both on emulator and phone. I tried it earlier with the same result. Maybe should I add something more? Not only to my broadcast receiver? – Grzes Jun 11 '11 at 18:01
  • I tried this instead of CAMERA_BUTTON, and it's working on emulator, but not on phone... I have HTC DESIRE Android 2.2. – Grzes Jun 11 '11 at 18:01
0

I don't think the camera button is functional in the emulator. Do you have any hardware devices you can try your app on?

Here's the relevant bug report: http://code.google.com/p/android/issues/detail?id=8197

If your up for messing with the emulator source code, you can try the instructions here: http://soledadpenades.com/2011/02/20/enabling-the-camera-button-in-androids-emulator/

Christopher Souvey
  • 2,890
  • 21
  • 21
  • As i wrote before, I had been testing it on my HTC desire 2.2, with the same result. there wasn't any toast. so that I guess I need to do something more in my code. permission? some more lines in manifest? – Grzes Jun 11 '11 at 21:02
  • Ok, I find something interesting: http://stackoverflow.com/questions/4389427/android-broadcastreceiver-intent-to-detect-camera-photo-taken So I give up using BroadcastReceiver, I'm going to do it with ContentObserver. Thanks for help :) – Grzes Jun 11 '11 at 21:53