Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android notification shown only icon on status bar

Tags:

android

In my application i wrote simple notification function, the method shows icon only on status bar and i want to show notification layout too, but not shown automatically and i have pull down android status bar down to see that,

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

It seems this problem is for android 6 and above

like image 593
mahdi pishguy Avatar asked Aug 10 '16 10:08

mahdi pishguy


2 Answers

For me this was solved by calling setDefaults(Notification.DEFAULT_ALL) on the builder. Hope that helps,

Paul

like image 127
Paul Avatar answered Nov 15 '22 19:11

Paul


Add .setLargeIcon(R.mipmap.ic_launcher) in your code

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

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

like image 36
SaravInfern Avatar answered Nov 15 '22 20:11

SaravInfern