Raj*_*ddy 5 android push-notification firebase firebase-cloud-messaging
我正在使用FCM进行通知,其中一切正常,但是直到应用程序打开,一旦我杀死(关闭)应用程序或在后台,我得到默认样式的通知,任何人都可以帮助我在应用程序时设置此通知样式已关闭(或任何其他建议).请帮助我,谢谢你提前
这是我的代码
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String title = "";
if (remoteMessage.getNotification().getTitle() != null){
title = remoteMessage.getNotification().getTitle();
}
String message = "";
if (remoteMessage.getNotification().getBody() != null){
message = remoteMessage.getNotification().getBody();
}
Log.e("notification","recieved");
sendNotification(title, message);
}
private void sendNotification(String title, String message) {
Intent intent = new Intent(this, MainActivity2.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0/*Request code*/, intent, PendingIntent.FLAG_ONE_SHOT);
Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
int color=getResources().getColor(R.color.dot_dark_screen2);
NotificationCompat.Builder notifiBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.account_outline)
.setColor(color)
.setDefaults(Notification.DEFAULT_SOUND)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
.setContentTitle(title)
.setContentText(message)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setAutoCancel(true)
.setSound(notificationSound)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /*ID of notification*/, notifiBuilder.build());
Run Code Online (Sandbox Code Playgroud)
我已经在这里发布了很长的解释: Android notification icon issues
长话短说:
您的问题很可能是notification-messages和data-messages之间的差异。
请阅读:https ://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
当您希望 FCM 代表您的客户端应用程序处理显示通知时,请使用通知消息。当您想要在客户端应用程序上处理消息时,请使用数据消息。
归档时间: |
|
查看次数: |
1494 次 |
最近记录: |