P
P
pthon2020-05-05 17:22:42
Android
pthon, 2020-05-05 17:22:42

Why doesn't the notification appear?

I'm trying to call a notification from the service, but for some reason it's not there.

//Notification
                            NotificationCompat.Builder builder =
                                    new NotificationCompat.Builder(context)
                                            .setSmallIcon(R.drawable.ic_notifications_black_24dp)
                                            .setContentTitle("Status")
                                            .setContentText("Voltage: "+currentVoltageStr)
                                            .setPriority(-2);
                            int NOTIFICATION_ID = 12345;

                            Intent targetIntent = new Intent(context, HomeFragment.class);
                            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                            builder.setContentIntent(contentIntent);
                            NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                            assert nManager != null;
                            nManager.notify(NOTIFICATION_ID, builder.build());

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pthon, 2020-05-05
@pthon

It was necessary to create a channel for notifications

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question