【发布时间】:2015-05-08 15:32:26
【问题描述】:
我刚刚在我的 Wear 设备上成功创建了一堆页面通知。
唯一的问题是 PendingIntent 似乎没有启动一个 Activity (当然是在 Manifest 中声明的)。
这是我的代码:
List extras = new ArrayList();
Intent viewIntent = new Intent(getApplicationContext(), DetailActivity.class);
viewIntent.putExtra("KEY", "TEST123");
//Note: I also tried: Intent viewIntent = new Intent(getApplicationContext(), DetailActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent viewPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, viewIntent, 0);
for (Route aRoute : myRoutes) {
Notification aNotif = new NotificationCompat.Builder(getApplicationContext())
.setContentTitle("BUS " + aRoute.route_short_name)
.setContentText(aRoute.directions.get(0).trip_headsign)
.setLargeIcon(bitmap)
.setContentIntent(viewPendingIntent)
.setSmallIcon(R.mipmap.ic_launcher).build();
extras.add(aNotif);
}
NotificationCompat.Builder builder1 = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(desc)
.setContentIntent(viewPendingIntent)//Just in case
.setSmallIcon(R.mipmap.ic_launcher);
Notification notification = builder1
.extend(new NotificationCompat.WearableExtender()
.addPages(extras))
.setContentIntent(viewPendingIntent)//Just in case
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(0, notification);
当我按下通知时,我希望意图启动,但没有任何反应..
欢迎提出任何建议。
编辑: 这段代码在通知之后就可以工作,因此,可以轻松启动第二个活动,而不会出现我们的错误:
startActivity(viewIntent);
编辑2: 现在末尾有一个“打开”按钮可以正常工作,但单个通知(每个页面)仍然没有任何反应
【问题讨论】:
-
当您转到“在手机上打开”操作时,会启动 Wear 设备上的内容意图 - 这是否正确启动了您的详细活动?
-
你好@ianhanniballake 上面的代码打开一个主通知(如预期),三个页面(如预期)和一个“阻止应用程序”按钮(默认情况下我猜)我不想显示“在手机上打开”操作。
-
确切地说:现在末尾有一个“打开”按钮可以正常工作,并在手表上打开活动,但个别通知(每页)仍然没有任何反应
标签: android android-intent notifications wear-os