使用 xml 内容实施 android 可扩展通知?
Implement android expandable notification with xml content?
我正在尝试使用操作按钮实现自定义通知
但是当我尝试实现它时,操作按钮和应用程序名称没有出现。
我的实现:
RemoteViews remoteViews = new
RemoteViews(getPackageName(),R.layout.emotions_notification);
Intent receiver = new Intent();
receiver.setAction("Action");
PendingIntent pendingIntentYes = PendingIntent.getBroadcast(this, 12345, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, "feelBetter.emotions")
.setContent(remoteViews)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_status_bar)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setColor(Color.parseColor("#322176"))
.setLights(Color.parseColor("#322176"), 1000, 1000)
.addAction(R.drawable.common_google_signin_btn_icon_dark_normal, "Action", pendingIntentYes)
.setSound(uri)
.setAutoCancel(true);
notificationManager = NotificationManagerCompat.from(this);
// notificationId is a unique int for each notification that you must define
notificationManager.notify(id, mBuilder.build());
如何实现?
试试这个
// Get the layouts to use in the custom notification
RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_small);
RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), R.layout.notification_large);
// Apply the layouts to the notification
Notification customNotification = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(notificationLayout)
.setCustomBigContentView(notificationLayoutExpanded)
.build();
我正在尝试使用操作按钮实现自定义通知
但是当我尝试实现它时,操作按钮和应用程序名称没有出现。
我的实现:
RemoteViews remoteViews = new
RemoteViews(getPackageName(),R.layout.emotions_notification);
Intent receiver = new Intent();
receiver.setAction("Action");
PendingIntent pendingIntentYes = PendingIntent.getBroadcast(this, 12345, receiver, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, "feelBetter.emotions")
.setContent(remoteViews)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_status_bar)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setColor(Color.parseColor("#322176"))
.setLights(Color.parseColor("#322176"), 1000, 1000)
.addAction(R.drawable.common_google_signin_btn_icon_dark_normal, "Action", pendingIntentYes)
.setSound(uri)
.setAutoCancel(true);
notificationManager = NotificationManagerCompat.from(this);
// notificationId is a unique int for each notification that you must define
notificationManager.notify(id, mBuilder.build());
如何实现?
试试这个
// Get the layouts to use in the custom notification
RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_small);
RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), R.layout.notification_large);
// Apply the layouts to the notification
Notification customNotification = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setStyle(new NotificationCompat.DecoratedCustomViewStyle())
.setCustomContentView(notificationLayout)
.setCustomBigContentView(notificationLayoutExpanded)
.build();