Android: how to listen to camera capture in Broadcastreceiver

I saw a lot of posts on StackOverflow about how to listen to camera events, and got some information, but there are still a few questions that remain in my mind, please let me know the answers to them:

I have an application in which there is a broadcast receiver, and my broadcast receiver will lautate my activity, but the main goal of having a broadcast receiver is to listen to the intent of the photo / video capture of the camera.

I want to know why I should listen to it, and whether it can be done.

thanks

+4
source share
3 answers

To get the intention to capture the camera camera, try the following code

public class CameraEventReciver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "New Photo Clicked", Toast.LENGTH_LONG).show(); } 

and in the manifest register the receiver: -

 <uses-permission android:name="android.permission.CAMERA" /> <receiver android:name="com.android.application.CameraEventReciver" android:enabled="true" > <intent-filter> <action android:name="com.android.camera.NEW_PICTURE" /> <data android:mimeType="image/*" /> </intent-filter> </receiver> 
+8
source

In your Android manifest, you should indicate what intentions you want to receive. For the camera, which will be the following code (this applies to the <application> tags):

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

In addition to this, you should add this to your <intent-filter> in the <activity> tags:

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

Finally, take care of the event in your activity code as follows:

 @Override public void onReceive(Context context, Intent intent) { abortBroadcast(); //TODO: your code here } 
+2
source

You can use a stream that will control your directory camera, for example:

 FileObserver observer =new FileObserver("/mnt/extSd/DCIM/Camera/"){ @Override public void onEvent(int event, String file) { // TODO Auto-generated method stub if(event == FileObserver.CREATE ){ //Do Some things With The file } }}; } catch (FileNotFoundException e) { e.printStackTrace(); } observer.startWatching(); 
0
source

All Articles