如何添加';大文本';或';收件箱样式';Firebase android项目的通知?
我正在尝试从Firebase控制台发送推送通知,目前我可以从Firebase控制台向虚拟设备发送消息,但如果消息很长,它将不会完全显示在通知栏中 这是Firebasemessagingservice的代码:如何添加';大文本';或';收件箱样式';Firebase android项目的通知?,android,firebase,push-notification,android-notifications,firebase-notifications,Android,Firebase,Push Notification,Android Notifications,Firebase Notifications,我正在尝试从Firebase控制台发送推送通知,目前我可以从Firebase控制台向虚拟设备发送消息,但如果消息很长,它将不会完全显示在通知栏中 这是Firebasemessagingservice的代码: import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.support.v4.app.Notificatio
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());
}
}
感谢Adib提供的详细答案,我已经有了一个PHP后端服务器,但是每当我尝试从服务器发送长通知时,它都不会完全显示,我的问题是我只能编辑代码的最后一部分,这样我就可以使用inboxStyle或bigtextstyle从服务器发送长通知
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());
}
鉴于此,您仍然无法以大通知样式通过Firebase发送推送通知。除非Firebase库添加此功能并开始支持它,否则推送通知将始终采用简单的单一通知样式
但是,您可以调整它以按自己的方式工作。但是要注意的是,如果您通过Firebase项目控制台的通知部分发送数据,则此过程不可能进行只有当您的应用程序具有后端并且推送通知通过web发送时,才能执行此操作。
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, whatToOpen, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(message)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setAutoCancel(true)
.setSmallIcon(R.drawable.push_icon_small)
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(),R.drawable.push_icon_large))
.setSound(defaultSoundUri)
.setColor(getResources().getColor(R.color.colorPrimary))
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
现在你甚至可以在推送通知中发送文章!希望这有帮助 您的问题到底是什么?如何编辑代码,以便在向虚拟设备发送通知时可以扩展通知。