为什么我不能开始从Android Wear页面通知的活动? [英] Why can't I start an Activity from a page Notification on Android Wear?

查看:250
本文介绍了为什么我不能开始从Android Wear页面通知的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚成功创建了一堆网页通知我穿的设备上。

唯一的问题是,的PendingIntent不似乎开始一个活动
(这是在清单中声明当然)。

下面是我的code:

 列表演员=新的ArrayList();
意图viewIntent =新意图(getApplicationContext(),DetailActivity.class);
viewIntent.putExtra(键,TEST123);
//注:我也尝试:意向viewIntent =新意图(getApplicationContext(),DetailActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
的PendingIntent viewPendingIntent = PendingIntent.getActivity(getApplicationContext(),0,viewIntent,0);对于(路线aRoute:myRoutes){
    通知aNotif =新NotificationCompat.Builder(getApplicationContext())
    .setContentTitle(BUS+ aRoute.route_short_name)
    .setContentText(aRoute.directions.get(0).trip_headsign)
    .setLargeIcon(位图)
    .setContentIntent(viewPendingIntent)
    .setSmallIcon(R.mipmap.ic_launcher).build();    extras.add(aNotif);
}NotificationCompat.Builder助洗剂=新NotificationCompat.Builder(本)
    .setContentTitle(职称)
    .setContentText(DESC)
    .setContentIntent(viewPendingIntent)//以防万一
    .setSmallIcon(R.mipmap.ic_launcher);通知通知=助洗剂
    .extend(新NotificationCompat.WearableExtender()
    .addPages(演员))
    .setContentIntent(viewPendingIntent)//以防万一
    。建立();NotificationManagerCompat notificationManager = NotificationManagerCompat.from(本);
    notificationManager.notify(0,通知);

当我美元通知书p $ PSS,我期待的意图开始,但没有任何反应。

任何建议是值得欢迎的。

编辑:
这code工作,只是通知后,那么,第二个活动可以很容易地全无错误启动:

  startActivity(viewIntent);

EDIT2:
现在有在工作正常结束的打开按钮,但仍没有发生在个别通知(每页)


解决方案

  1. 页面是不能点击 - 在Android Wear,只有动作是可以点击的。对于手机生成的通知,那些只出现在所有页面后

  2. 如果你有你的手机上的内容原意生成的通知,将始终显示为在手机上打开采取行动。有没有方法来禁用,除非你删除内容的意图(使通知无法点击的电话)。

我说'手机产生的,你也可以创建Wear应用。通过使用数据层将邮件推送到您的Wear应用,那么Wear应用可以建立自定义通知。这些通知让您使用<一个href=\"https://developer.android.com/reference/android/app/Notification.WearableExtender.html#setDisplayIntent(android.app.PendingIntent)\"相对=nofollow> setDisplayIntent()并显示在线活动(无论是作为主网页或作为单独的页面)。这些活动可以,当然包含任何需要的视图,包括采取行动执行任何操作(如发送一条消息回电话启动特定活动)。

请注意,由于页面默认情况下不点击,一个自定义通知的造型应该使它非常明显的项目是可以点击的。而不是使用自定义通知活动,你可以考虑使用<一个href=\"https://developer.android.com/reference/android/app/Notification.WearableExtender.html#setContentAction(int)\"相对=nofollow> setContentAction()显示与布局的其余部分的操作图标在线 - 这个删除行动过去的动作,并把它通知/页直接在一个单独的元素。

I just succesfully created a bunch of pages notifications on my Wear device.

The only problem is that the PendingIntent does not seems to start an Activity (which is of course declared in Manifest).

Here is my code:

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

When I press on a Notification, I expect the intent to start, but nothing happens..

Any suggestion is welcome.

EDIT: This code works, just after the notification, so, the second activity can easily be launched withour bug:

 startActivity(viewIntent);

EDIT2: There is now an "open" button at the end that works fine, but still nothing happens on individual notifications (every pages)

解决方案

  1. Pages are not clickable - on Android Wear, only actions are clickable. For phone generated notifications, those only appear after all pages
  2. If you have a content intent on your phone generated notification, that will always appear as an 'Open on phone' action. There is no way to disable this unless you remove your content intent (making the notification unclickable on phones).

I say 'phone generated' as you can also create a Wear app. By using the data layer to push messages to your Wear app, the Wear app can then build custom notifications. These notifications allow you to use setDisplayIntent() and display activities inline (either as the main page or as separate pages). These activities can, of course, contain any View you want, including actions to perform any action (such as send a message back to the phone to start a particular activity).

Note that because pages are not clickable by default, styling of a custom notification should make it very obvious that the items are clickable. Rather than using a custom notification activity, you may consider using setContentAction() to display the action icon inline with the rest of the layout - this removes the action as a separate element past the action and places it directly on the notification/page.

这篇关于为什么我不能开始从Android Wear页面通知的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆