安卓(Android) 怎么设置大通知(Notification)

2019年10月7日22:04:15安卓(Android) 怎么设置大通知(Notification)已关闭评论 297 1186字阅读3分57秒

1.简介

安卓(Android) 怎么设置大通知(Notification)?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v4.app.NotificationCompat;

public class Main {

    public static void setBigNotification(Context context, String title,
            String content, String[] lines, String ticker, int num,
            int sIcon, Bitmap bIcon, Class<?> cls) {
        NotificationManager manager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context);
        mBuilder.setNumber(num);
        mBuilder.setSmallIcon(sIcon);
        mBuilder.setLargeIcon(bIcon);
        
        mBuilder.setTicker(ticker);
        
        mBuilder.setAutoCancel(true);

        
        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

        for (String line : lines) {
            style.addLine(line);
        }
        style.setBigContentTitle(title);
        style.setSummaryText(content);
        mBuilder.setStyle(style);

        Intent intent = new Intent(context, cls);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                intent, PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(pendingIntent);
        manager.notify(0, mBuilder.build());
    }
}

 
继续阅读
编程十万个怎么办