How to generate a notification when taking a new picture with a camera application?

I want to create a notification from my application when a new image is taken from the camera application. I want to achieve this when my application is not working. For this I use a broadcast receiver. Here is my code ...

In the Android manifest.

<receiver
    android:name=".receivers.CameraEventReceiver"
    android:label="CameraEventReceiver"
    android:enabled="true">
    <intent-filter>
        <action android:name="android.hardware.action.NEW_PICTURE" />

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

In the receiver class

public class CameraEventReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {

            NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){

                NotificationChannel channel = new NotificationChannel("CHANNEL_ID", "my channel name", NotificationManager.IMPORTANCE_HIGH);
                manager.createNotificationChannel(channel);
            }
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "CHANNEL_ID")
                    .setColor(ContextCompat.getColor(context, R.color.colorPrimary))
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("Picture Taken")
                    .setContentText("here is the uri : "+intent.getData())
                    .setDefaults(NotificationCompat.DEFAULT_VIBRATE)
                    .setAutoCancel(true);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.O){
                builder.setPriority(NotificationCompat.PRIORITY_HIGH);
            }

            manager.notify(222, builder.build());
        }
    }

It works great for Android 6.0 when the application works ... But it does not work for newer versions. What can be done to achieve this? I want it to support all devices with Android versions greater than 4.1 (JELLY_BEAN)

Thanks in advance

+4
source share
1 answer

.

. . Android 7.0 .

?

, ACTION_IMAGE_CAPTURE, API- (, Fotoapparat, CameraKit-Android).

, , .

JobScheduler addTriggerContentUri() <23 > . , , , .

0

Source: https://habr.com/ru/post/1695605/


All Articles