繁体   English   中英

我没有收到奥利奥和上层的通知

[英]I'm not getting notifications Oreo and upper

我必须使通知在android oreo和上层工作,但没有显示,我该如何解决我的问题? 我尝试从android developers.com实施实现指令,但没有帮助,有人可以用此代码帮助我吗? 对不起,我的英语不好。

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);
                    }
                }

从Android 8开始,所有通知都必须分配给NotificationChannel 在这里您可以找到有关它的信息。

希望对你有帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM