Android - 抬头通知问题

时间:2018-06-13 20:17:23

标签: java android android-studio

我在使用android时遇到麻烦。有没有人知道什么是缺少让它们出现在我的模拟器上?我已经阅读了很多关于抬头通知的主题,而且我尝试的所有内容都没有用。提前致谢

private void createNotificationChannel() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            CharSequence name = "channelInality";
            String description = "channelDescription";
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel channel = new NotificationChannel(mNotificationChannel, name, importance);
            channel.setDescription(description);
            channel.enableLights(true);
            channel.enableVibration(true);

            NotificationManager notificationManager = InalityAppController.getInstance().getContext().getSystemService(NotificationManager.class);
            notificationManager.createNotificationChannel(channel);
        }
    }

    public void createNotification(String pTitle, String pContent) {

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(InalityAppController.getInstance().getContext());

        NotificationCompat.Builder notification = new NotificationCompat.Builder(InalityAppController.getInstance().getContext(), mNotificationChannel);
        notification.setSmallIcon(R.drawable.ic_action_people);
        notification.setContentTitle(pTitle);
        notification.setContentText(pContent);
        notification.setAutoCancel(true);
        notification.setPriority(NotificationCompat.PRIORITY_HIGH);
        if (Build.VERSION.SDK_INT >= 21) {
            notification.setVibrate(new long[0]);
        }

        notificationManager.notify(mNotificationID, notification.build());
        mNotificationID++;
    }

0 个答案:

没有答案