2016-04-07 88 views
0

我試圖創建一個通知,它在展開後完全更改其文本。在擴展通知後更新Android中的通知文本

例如,正常的非擴展通知會像「點擊做X」那樣有待處理意圖。

如果用戶擴展通知,那麼文本會更改爲在添加到通知中的一些操作時會顯示「以下是您可以執行的操作」。

回答

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());