小编kaz*_*ama的帖子

如何为此 Firebase Android 项目添加“大文本”或“收件箱样式”通知?

我正在尝试从 Firebase 控制台发送推送通知,目前我可以从 Firebase 控制台向我的虚拟设备发送消息,但如果消息很长,则不会完全显示在通知栏中。

这是 Firebasemessagingservice 的代码:

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

import com.google.firebase.messaging.RemoteMessage;

/**
 * Created by filipp on 5/23/2016.
 */
public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService{

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {

        showNotification(remoteMessage.getData().get("message"));
    }

    private void showNotification(String message) {

        Intent i = new Intent(this,MainActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setAutoCancel(true)
                .setContentTitle("Elit")
                .setContentText(message)
                //.setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentIntent(pendingIntent);

        NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        manager.notify(0,builder.build());
    }


}
Run Code Online (Sandbox Code Playgroud)

感谢 Adib 的详细回答,我已经有一个 PHP 后端服务器,但是每当我尝试从服务器发送长通知时,它都不会完全显示,我的问题是我是否可以只编辑代码的最后一部分,以便我可以发送长通知使用 inboxStyle 或 …

android push-notification android-notifications firebase firebase-notifications

5
推荐指数
1
解决办法
4902
查看次数