问题描述
我在我的收藏申请已更新的数据,并在多个页面显示这些数据的情况。
I am in a case where my Watch application has updated data and will display these data in multiple pages.
根据这样的回答:,我创建了一个displayIntent我的网页中的每一个。
According to this answer: http://stackoverflow.com/a/30133449/327402 , I created a displayIntent for each one of my page.
List extras = new ArrayList();
//This is a loop to create every individual Notification
for (Route aRoute : myRoutes) {
Intent viewIntent = new Intent(getApplicationContext(), MainActivity.class);
String toSend = aRoute.detail;
Log.d("CVE",toSend);
viewIntent.putExtra("KEY", toSend);
PendingIntent displayendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification aNotif = new NotificationCompat.Builder(getApplicationContext())
.setLargeIcon(bitmap)
.extend(new NotificationCompat.WearableExtender()
.setDisplayIntent(displayendingIntent)
.setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM))
.setSmallIcon(R.mipmap.ic_launcher)
.build();
extras.add(aNotif);
}
//This is "main" notification.
NotificationCompat.Builder builder1 = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(desc)
.setSmallIcon(R.mipmap.ic_launcher);
Notification notification = builder1
.extend(new NotificationCompat.WearableExtender()
.addPages(extras))
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(0, notification);
到这里,它看起来不错,但是当我阅读每个通知会发生什么,我才知道的数据是一样的。
Till here, it looks OK, but when I read what happens on every notification, I realize that the data is the same.
这是我的简化的活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.text_view);
mTextView.setText("Value: "+getIntent().getStringExtra("KEY"));
}
问题是,日志(见code的第一部分部分第6行)正确显示:
The problem is that the Log (see line 6 of the first part part of the code) displays correctly:
文本1
文本2
文本3
"Text 1""Text 2""Text 3"
,但在现实中,文本3显示在每一个通知!
, but in reality, "Text 3" is displayed in every Notification!
我应该如何解决这个问题?
How should I fix this?
推荐答案
不要使用0作为请求code你的PendingIntent,但是每一个不同的独特的价值反对您的请求。例如。
Don't use 0 as request code for your PendingIntent, but a different unique value for each object your request. E.g.
int counter = 0;
for (Route aRoute : myRoutes) {
// other code
PendingIntent displayendingIntent
= PendingIntent.getActivity(getApplicationContext(), counter++,
viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// other code
}
这篇关于传递不同的附加功能,以不同的setDisplayIntent,但同样是收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!