Broadcast Receiver Won't Receive Camera Event

How to get camera click event with the help of broadcast receiver?

I solved the ClassNotFoundException by making the CameraReceiver class public. I implemented your code on my android project, and got the ClassNotFoundException but i solved it now. Just change your class as following and also change the first parameter of Toast as I did in the following code.

public class CameraReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
abortBroadcast();
Log.d("New Photo Clicked", ">");
Cursor cursor = context.getContentResolver().query(
intent.getData(), null, null, null, null);
cursor.moveToFirst();
String image_path = cursor
.getString(cursor.getColumnIndex("_data"));
Toast.makeText(context, "New Photo is Saved as : " + image_path,
1000).show();
}

}

and it should work, it is working for me, when I take picture from camera. Remove the class from MainActivity and create a separate public CameraReceiver class for above code.

Android: Broadcast receiver won't receive boot up message

Try the following:

<receiver android:name=".MyBroadcastReceiverX"  android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED">
<category android:name="android.intent.category.DEFAULT"/>
</action>
</intent-filter>
</receiver>

You also have incorrect class name specified in manifest - it should be MyBroadcastReceiverX rather then MyBroadcastReceiver

Broadcast Receiver not getting the broadcast if app is not started

Apparently in Android 3.1+, apps are in a stopped state if they have never been run, or have been force stopped. The system excludes these apps from broadcast intents. They can be included by using the Intent.FLAG_INCLUDE_STOPPED_PACKAGES flag.

http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html

http://developer.android.com/sdk/android-3.1.html#launchcontrols

Also, I think you need the Intent.FLAG_ACTIVITY_NEW_TASK flag.

Broadcast Receivers not working in Android 6.0 Marshmallow

Your app's target API level is 23, that is android M (6.0). In android M there are huge changes related to user-permissions.
Here is nice article explaining the changes.

Listen to photo taken event

Found a way by registering to all sub directories of dcim (except the ones that start with a period):

new FileObserver(dcimDir.toString(), FileObserver.CLOSE_WRITE)

The reason I need to register to all of them is because different phones put picutes and videos in different folders - at least they are all under DCIM.

The reason the event is 'CLOSE_WRITE' is because I want to trigger after the photo/video is complete, so I won't process only half of the photo/video.

Android camera intent and get the pic from the camera

You might want to consider showing the camera inside a view in your app and bypassing the standard camera app entirely. If you're curious about doing this, here are some good resources to get you started:

  • http://developer.android.com/reference/android/hardware/Camera.html
  • http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/CameraPreview.html


Related Topics



Leave a reply



Submit