无法扩展Firebase通知

问题描述:

我已经使用Firebase身份验证和消息发送应用程序,但我一直通过Firebase控制台向应用程序发送通知,问题是如果它很大,我无法展开通知。我该怎么做?帮助我无法扩展Firebase通知

public class FirebaseNots extends FirebaseMessagingService { 


private static final String TAG = "MyFirebaseMsgService"; 

/** 
* Called when message is received. 
* 
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging. 
*/ 
// [START receive_message] 
@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 
    // [START_EXCLUDE] 
    // There are two types of messages data messages and notification messages. Data messages are handled 
    // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type 
    // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app 
    // is in the foreground. When the app is in the background an automatically generated notification is displayed. 
    // When the user taps on the notification they are returned to the app. Messages containing both notification 
    // and data payloads are treated as notification messages. The Firebase console always sends notification 
    // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options 
    // [END_EXCLUDE] 

    // TODO(developer): Handle FCM messages here. 
    // Not getting messages here? See why this may be: 
    Log.d(TAG, "From: " + remoteMessage.getFrom()); 

    // Check if message contains a data payload. 
    if (remoteMessage.getData().size() > 0) { 
     Log.d(TAG, "Message data payload: " + remoteMessage.getData()); 
    } 

    // Check if message contains a notification payload. 
    if (remoteMessage.getNotification() != null) { 
     Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); 
    } 

    // 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. 
} 
// [END receive_message] 

/** 
* Create and show a simple notification containing the received FCM message. 
* 
* @param messageBody FCM message body received. 
*/ 
private void sendNotification(String messageBody) { 
    Intent intent = new Intent(this, MainActivity.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, 
      PendingIntent.FLAG_ONE_SHOT); 

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
      .setSmallIcon(R.drawable.ic) 
      .setContentTitle("FCM Message") 
      .setContentText(messageBody) 
      .setAutoCancel(true) 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent); 

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); 
} 
    } 

Image Please Take A Look

感谢

您需要添加一个BigTextStyle到您的通知,如果你希望它是可扩展的,以显示多行:

从火力地堡
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle() 
    .bigText(messageBody)); 
+0

我已经做到了这一点,但仍然没有工作:( –

+0

您的代码实际上并没有打电话给你'sendNotification()'方法 - 你在哪里调用它? – ianhanniballake

+0

我在哪里需要调用它? –

通知控制台还不支持BigStyle通知。这是一个已知问题,他们正在努力解决问题,因为解决方法是使用数据消息使用REST API发送通知,然后在收到消息时自己生成通知,如@ianhanniballake所建议的那样。

+0

感谢man!我对这个新东西不熟悉,你有任何教程或任何我可以进一步处理的东西吗? –

+0

请参阅FCM文档:https://firebase.google.com/docs/cloud-messaging/downstream和Android通知文档:https://developer.android.com/guide/topics/ui/notifiers/notifications.html。 –

此行为在即将发布的FCM的下一个版本中得到修复。

请关注https://firebase.google.com/support/releases下一个Android的发布和更新库的版本在你的应用程序:)