android 推送图标大小,java - 如何在推送通知到达Android后立即更改家庭活动中的通知图标 - 堆栈内存溢出...

您可以使用自定义接收器firebase Clude消息

在你的表现

android:name=".ReciverClass.MyFirebaseMessagingService"

android:exported="false">

和你的接收者

public class MyFirebaseMessagingService extends FirebaseMessagingService {

/**

* Called when message is received.

*

* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.

*/

@Override

public void onMessageReceived(RemoteMessage remoteMessage) {

super.onMessageReceived(remoteMessage);

// TODO(developer): Handle FCM messages here.

// If the application is in the foreground handle both data and notification messages here.

// Also if you intend on generating your own notifications as a result of a received FCM

// message, here is where that should be initiated. See sendNotification method below.

RemoteMessage.Notification notification = remoteMessage.getNotification();

Map data = remoteMessage.getData();

sendNotification(notification, data);

}

private void sendNotification(RemoteMessage.Notification notification, Map data) {

Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);

Intent intent = new Intent(this, MainActivity.class);

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "channel_id")

.setContentTitle(notification.getTitle())

.setContentText(notification.getBody())

.setAutoCancel(true)

.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))

.setContentIntent(pendingIntent)

.setContentInfo(notification.getTitle())

.setLargeIcon(icon)

.setColor(Color.RED)

.setLights(Color.RED, 1000, 300)

.setDefaults(Notification.DEFAULT_VIBRATE)

.setSmallIcon(R.mipmap.ic_launcher);

try {

String picture_url = data.get("picture_url");

if (picture_url != null && !"".equals(picture_url)) {

URL url = new URL(picture_url);

Bitmap bigPicture = BitmapFactory.decodeStream(url.openConnection().getInputStream());

notificationBuilder.setStyle(

new NotificationCompat.BigPictureStyle().bigPicture(bigPicture).setSummaryText(notification.getBody())

);

}

} catch (IOException e) {

e.printStackTrace();

}

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

// Notification Channel is required for Android O and above

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

NotificationChannel channel = new NotificationChannel(

"channel_id", "channel_name", NotificationManager.IMPORTANCE_DEFAULT

);

channel.setDescription("channel description");

channel.setShowBadge(true);

channel.canShowBadge();

channel.enableLights(true);

channel.setLightColor(Color.RED);

channel.enableVibration(true);

channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500});

notificationManager.createNotificationChannel(channel);

}

notificationManager.notify(0, notificationBuilder.build());

}}

祝好运

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值