Android: BroadcastReceiver intent to Detect Camera Photo Taken?

扶醉桌前 提交于 2019-11-26 11:04:27

问题


I\'m working on an Android application which needs to perform an action each time a new image is taken with the phone. I don\'t want to take the image within my application, but rather perform some action when the Camera app takes an image and saves it to the SD card. Right now, I\'ve gotten a BroadcastReceiver implemented that\'s currently listening for \"android.intent.action.CAMERA_BUTTON\". However, this doesn\'t seem to get called when I\'m wanting it to. I\'ve tried to debug the application on my own phone with a linebreak on the first line of the BroadcastReceiver\'s OnReceive method, but it never reaches that code.

Does anyone know what the correct intent for which I should be listening is? Or is using a BroadcastReceiver not even the best way to do this? (For example, is there a better way to accomplish this such as listening for when a new image is saved to the card)?

Thanks!

Update: I do have a Trackball on my phone (HTC Eris), so is it possible that taking photos that way doesn\'t get sent as \"Camera Button\"? If so, is there a workaround for a phone without a \"Camera Button\", but rather something like a Trackball?


回答1:


Right now, I've gotten a BroadcastReceiver implemented that's currently listening for "android.intent.action.CAMERA_BUTTON". However, this doesn't seem to get called when I'm wanting it to.

That only gets broadcast if the foreground activity does not consume the event.




回答2:


Quite an old question, if anyone still needs the solution try using

android.hardware.action.NEW_PICTURE

as your intent filter

<!-- Receiver for camera clicks -->
    <receiver
        android:name=".receivers.CameraEventReceiver"
        android:label="CameraEventReceiver">
        <intent-filter>

            <!-- <action android:name="com.android.camera.NEW_PICTURE" /> -->
            <action android:name="android.hardware.action.NEW_PICTURE" />

            <data android:mimeType="image/*" />
        </intent-filter>
    </receiver>

It will return the Uri of the image in intent.getData() of its onReceive() function

Hope it helps




回答3:


try this one this works for me

<receiver android:name=".pictureReceiver" >
        <intent-filter android:priority="10000" >
            <action android:name="android.intent.action.CAMERA_BUTTON" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
</receiver>


来源:https://stackoverflow.com/questions/4389427/android-broadcastreceiver-intent-to-detect-camera-photo-taken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!