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

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

public class MyNotificationService extends FirebaseMessagingService {

public void onMessageReceived(RemoteMessage remoteMessage) {
    // do nothing
}

@Override
public 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());
}

}

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值