您好我正在使用Firebase在Android中实现推送通知。现在,在一个圆圈内有一个小图标。我需要它以更大的尺寸显示。请看图像。这是我的代码,
android:id="@+id/relativeNotification"
android:layout_width="192dp"
android:layout_height="192dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true">
<com.inspius.coreapp.widget.TintableImageView
android:layout_width="192dp"
android:layout_height="192dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_launcher"
app:tint="@color/custom_icon_video_detail_selector" />
如何从这个小图标中设置大图标?
答案 0 :(得分:3)
我认为可以通过覆盖默认设置来完成。
在您的申请清单中:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_icon" />
使用您的图标代替@drawable/notification_icon
。
希望有所帮助
更新:另外,看看:
https://github.com/firebase/quickstart-android/issues/4#issuecomment-221344318
icon参数可用于指定应用内的drawable。 如果你想使用R.drawable.foo,只需传递foo。
以下是icon
参数文档:
https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support
答案 1 :(得分:2)
请参阅只有当您的应用位于前台时,您才能自定义火力显示通知。
您的通知将被 FirebaseMessagingService 服务的 onMessageReceived 方法捕获
在应用处于前台时自定义通知。
从应用程序可绘制文件夹中放置图标
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.icons);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setLargeIcon(largeIcon)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody());
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
将图标从API“icon”标记
String name = remoteMessage.getNotification().getIcon();
URL url_value = new URL(name);
Bitmap mIcon1 = BitmapFactory.decodeStream(url_value.openConnection().getInputStream());
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setLargeIcon(mIcon1)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getNotification().getTitle()) .setContentText(remoteMessage.getNotification().getBody());
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
答案 2 :(得分:2)
我试着做同样的事情。覆盖“handleIntent”方法对我有用。我想删除super.handleIntent(intent)使这项工作成功。然后我们可以构建自己的通知来设置大图标。前景和后台情况都会调用此方法。像这样:
public class YourMessagingService extends FirebaseMessagingService {
@Override
public void handleIntent(Intent intent) {
// super.handleIntent(intent);
// get intent codes....
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Notification notification = builder
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.yourLargeIcon))
.setSmallIcon(R.drawable.yourSmallIcon)
.setContentTitle("yourTitle")
.setContentText("yourText")
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(111, notification);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
@Override
public void onDeletedMessages() {
super.onDeletedMessages();
}
}