我试图创建一个在展开后完全更改其文本的通知。
例如,正常的非扩展通知会说"点击做X"这将有一个未决的意图。
如果用户展开通知,则文本将更改为"以下是您可以执行的一些操作"将一些操作添加到通知中。
答案 0 :(得分:1)
设置通知构建器,如下所示:
NotificationCompat.Builder builder=new NotificationCompat.Builder(mContext);
builder.setContentTitle("Title!");
builder.setContentText("Tap to do x");
builder.setTicker("Ticker");
builder.setSmallIcon(drawable);
builder.setAutoCancel(true);
builder.addAction(icon, "Open App", resultPendingIntent)
builder.setContentIntent(resultPendingIntent)
builder.setPriority(Notification.PRIORITY_MAX);
//Content hen expanded
NotificationCompat.BigTextStyle bigText=new NotificationCompat.BigTextStyle();
bigText.bigText("Here are some actions you can do");
bigText.setSummaryText("Summary line");
bigText.setBigContentTitle("expanded title");
builder.setStyle(bigText);
Intent intent=new Intent(mContext, YourActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
stackBuilder.addParentStack(ParentActivity.class);
stackBuilder.addNextIntent(intent);
PendingIntent pendingIntent=stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
NotificationManager manager=(NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());