首页 > 学院 > 开发设计 > 正文

firebase推送 修改系统默认notification样式(稀有)

2019-11-09 18:42:09
字体:
来源:转载
供稿:网友

firebase在app前台时执行onMessageReceived方法,可以自定义样式,但是在app后台或被杀死时,不执行onMessageReceived方法,所以需要重写firebase的zzm方法才可以更改系统的默认样式

public class MyNotificationService extends FirebaseMessagingService {

public void onMessageReceived(RemoteMessage remoteMessage) { // do nothing}@Overridepublic void zzm(Intent intent) { Intent launchIntent = new Intent(this, SplashScreenActivity.class); launchIntent.setAction(Intent.ACTION_MAIN); launchIntent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* R equest code */, launchIntent, PendingIntent.FLAG_ONE_SHOT); Bitmap rawBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notification) .setLargeIcon(rawBitmap) .setContentTitle(intent.getStringExtra("gcm.notification.title")) .setContentText(intent.getStringExtra("gcm.notification.body")) .setAutoCancel(true) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());}

}


上一篇:抓包Fidder

下一篇:源代码之Git团队开发

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表