Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: BroadcastReceiver intent to Detect Camera Photo Taken?

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?

like image 955
JToland Avatar asked Dec 08 '10 15:12

JToland


2 Answers

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.

like image 131
CommonsWare Avatar answered Oct 01 '22 20:10

CommonsWare


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

like image 29
sanket vetkoli Avatar answered Oct 01 '22 18:10

sanket vetkoli