我正在通过可穿戴式应用发送包含多个页面的通知。对于每个datamapItem,都有一个单独的页面,其中包含contentAction。内容操作将调用一个新的活动,并从datamapitem中提交一个“ id”。此“ id”应显示在新的活动中
创建通知的ListenerService:
for (int i=dataMapItem.getDataMap().size()-1; i>=0; i--) {
...
Intent detailIntent = new Intent(this, DetailActivity.class);
detailIntent.putExtra(DetailActivity.EXTRA_ID, id);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Action action = new Notification.Action(R.drawable.btn_blue_small, "open", pendingIntent);
actions.add(action);
if(i!=0) {
Notification notificationPage = new Notification.Builder(this)
.setContentTitle(title)
.setContentText(text)
.extend(new Notification.WearableExtender()
.setBackground(colorBitmap)
.setContentAction(i)
)
.build();
pages.add(notificationPage);
} else {
Notification.Builder notificationBuilder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)
.setContentText(text)
.extend(new Notification.WearableExtender()
.addActions(actions)
.addPages(pages)
.setContentAction(i)
.setBackground(colorBitmap)
.setHintHideIcon(true)
);
Notification notification = notificationBuilder.build();
notification.defaults |= Notification.DEFAULT_VIBRATE;
((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
.notify(NOTIFICATION_ID, notification);
}
}
SecondActivity应该显示通过intent.putextra()提交的数据
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
mTextid = (TextView) findViewById(R.id.txtid);
Intent intent = getIntent();
if(intent != null) {
id = intent.getStringExtra(EXTRA_ID);
...
}
所以这是我的问题:由于我的putExtra的Key是静态的,因此在每次循环运行中,该值都会被覆盖。并且secondactiviy中的Displayed id始终为0,或者是最后一次遍历的值。
我希望我将其描述为可以理解的;)有人对此问题有解决方案吗?谢谢
由我自己解决。Itw只是一个愚蠢的错误。如果有人在乎,那只是挂起意图中的错误参数。
它应该是:
PendingIntent pendingIntent = PendingIntent.getActivity(this, index,
detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);
代替:
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
detailIntent, PendingIntent.FLAG_UPDATE_CURRENT);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句