I'm not getting notifications Oreo and upper

0

i have to make notification work on android oreo and upper but its not showing, how can i solve my problem? i tried implement instruction from android developers.com but its not helped, anyone can help me with this code? and sorry for my bad english.

if (newCount > 0) {
if (PrefUtils.getBoolean(PrefUtils.NOTIFICATIONS_ENABLED, true)) {
                        Cursor cursor = getContentResolver().query(EntryColumns.CONTENT_URI, new String[]{Constants.DB_COUNT}, EntryColumns.WHERE_UNREAD, null, null);

                        cursor.moveToFirst();
                        newCount = cursor.getInt(0); // The number has possibly changed
                        cursor.close();

                        if (newCount > 0) {
                            String text = getResources().getQuantityString(R.plurals.number_of_new_entries, newCount, newCount);

                            Intent notificationIntent = new Intent(FetcherService.this, HomeActivity.class);
                            PendingIntent contentIntent = PendingIntent.getActivity(FetcherService.this, 0, notificationIntent,
                                    PendingIntent.FLAG_UPDATE_CURRENT);

                            Notification.Builder notifBuilder = new Notification.Builder(MainApplication.getContext()) //
                                    .setContentIntent(contentIntent) //
                                    .setSmallIcon(R.drawable.ic_statusbar_rss) //
                                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) //
                                    .setTicker(text) //
                                    .setWhen(System.currentTimeMillis()) //
                                    .setAutoCancel(true) //
                                    .setContentTitle(getString(R.string.spaRSS_feeds)) //
                                    .setContentText(text) //
                                    .setLights(0xffffffff, 0, 0);

                            if (PrefUtils.getBoolean(PrefUtils.NOTIFICATIONS_VIBRATE, false)) {
                                notifBuilder.setVibrate(new long[]{0, 1000});
                            }

                            String ringtone = PrefUtils.getString(PrefUtils.NOTIFICATIONS_RINGTONE, null);
                            if (ringtone != null && ringtone.length() > 0) {
                                notifBuilder.setSound(Uri.parse(ringtone));
                            }

                            if (PrefUtils.getBoolean(PrefUtils.NOTIFICATIONS_LIGHT, false)) {
                                notifBuilder.setLights(0xffffffff, 300, 1000);
                            }

                            if (Constants.NOTIF_MGR != null) {
                                Constants.NOTIF_MGR.notify(0, notifBuilder.getNotification());
                            }
                        }
                    } else if (Constants.NOTIF_MGR != null) {
                        Constants.NOTIF_MGR.cancel(0);
                    }
                }
java
android
notifications
asked on Stack Overflow Feb 18, 2019 by Sergey Petrosyan • edited Feb 18, 2019 by Phantômaxx

1 Answer

1

Starting from the Android 8 all notifications must be assigned to a NotificationChannel. Here you can find information about it.

Hope it will help

answered on Stack Overflow Feb 18, 2019 by Stanislav Shamilov

User contributions licensed under CC BY-SA 3.0