开发者

Broadcast receiver android >= 2.2 CAMERA_BUTTON

开发者 https://www.devze.com 2023-03-12 10:31 出处:网络
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:

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.


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>


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


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号