我需要任何示例来创建通知的自定义布局并将其链接到我的 flutter 应用程序以进行 firebase 推送通知。任何人对此有任何了解请帮助我。谢谢。
我的应用程序 firebase 推送通知需要此类通知。
我已经使用RemoteViews小部件实现了自定义通知.我在Android 5.0.2和Android 6.0上测试过它.它工作正常.但过了一段时间,它每次收到GCM的通知时都会崩溃.
崩溃转储 -
Process: package.name, PID: 27743
android.app.RemoteServiceException: Bad notification posted from package package.name: Couldn't expand RemoteViews for: StatusBarNotification(pkg=package.name user=UserHandle{0} id=1524095391 tag=null key=0|package.name|1524095391|null|10247: Notification(pri=0 contentView=package.name/0x7f040033 vibrate=null sound=null defaults=0x0 flags=0x10 color=0x00000000 category=recommendation vis=PUBLIC))
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Run Code Online (Sandbox Code Playgroud)
我的RemoteViews布局在LinearLayout中有Imageview,自定义TextView类扩展TextView.
我创建通知的代码是
private void showCustomNotification(ABCNotification notification) {
RemoteViews notificationView = new RemoteViews(getPackageName(), R.layout.layout_notification);
PendingIntent contentPendingIntent = PendingIntent.getBroadcast(mContext, 0, notification.getContentIntent(), PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
builder.setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(contentPendingIntent);
// Set Notification Priority
builder.setPriority(notification.getNotificationPriority()); …Run Code Online (Sandbox Code Playgroud) notifications android push-notification remoteview custom-notification