(重复)Android工作室,不会显示通知

时间:2017-12-13 16:00:40

标签: java android android-notifications

这是我的添加通知方法:

private void addNotification() {
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher_background)
                    .setContentTitle("Notifications Example")
                    .setContentText("This is a test notification");

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);

    // Add as notification
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(0, builder.build());
}

在onCreate方法中,我有addNotification();因为我想在应用程序启动时发生通知。

已解决:Notifications fail to display in Android Oreo (API 26)

0 个答案:

没有答案