Android通知仅显示状态栏上的图标

mah*_*guy 10 android

在我的应用程序中,我写了简单的通知功能,该方法只显示状态栏上的图标,我也想显示通知布局,但没有自动显示,我已经下拉Android状态栏,看到,

public static void createNotification(Context context, Class activity, String title, String subject, int count_unread_message) {

    Intent intent = new Intent(context, activity);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);

    Notification notify = new NotificationCompat.Builder(context)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentText(subject)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setNumber(count_unread_message)
            .setPriority(0)

            .setLights(Color.BLUE, 500, 500)
            .setContentIntent(pendingIntent)
            .build();

    notify.flags |= Notification.FLAG_AUTO_CANCEL;

    NOTIFICATIONMANAGER = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
    NOTIFICATIONMANAGER.notify(159753456, notify);
}
Run Code Online (Sandbox Code Playgroud)

看来这个问题适用于Android 6及以上版本

Sar*_*ern 1

添加.setLargeIcon(R.mipmap.ic_launcher)您的代码

Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
                                           R.drawable.yourIcon);

 Notification notify = new NotificationCompat.Builder(context)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentText(subject)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(icon)//can set only bitmap images convert your drawable to bitmap
            .setNumber(count_unread_message)
            .setPriority(0)

            .setLights(Color.BLUE, 500, 500)
            .setContentIntent(pendingIntent)
            .build();
Run Code Online (Sandbox Code Playgroud)

https://developer.android.com/reference/android/app/Notification.html#largeIcon