SoFunction
Updated on 2025-03-11

Introduction to the implementation method of Android message notification bar


//Message notification column
//Define NotificationManager
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
//Define the content information displayed in the notification column
        int icon = ;
CharSequence tickerText = "My notification column title";
        long when = ();
        Notification notification = new Notification(icon, tickerText, when);

//Define the content information to be displayed when the drop-down notification bar is
        Context context = getApplicationContext();
CharSequence contentTitle = "My notification bar label expand title";
CharSequence contentText = "My notification bar expands details";
        Intent notificationIntent = new Intent(this, );
        PendingIntent contentIntent = (this, 0,
                notificationIntent, 0);
        (context, contentTitle, contentText,
                contentIntent);

//Use mNotificationManager's notify user to generate title bar message notification
        (1, notification);