【问题标题】:Activities inside Wear notificationsWear 通知中的活动
【发布时间】:2014-08-08 15:13:30
【问题描述】:

我需要在用户滑动到通知的下一页时启动的 Wear 设备上实现全屏活动 - 例如演示卡“登机牌”(第二页上的二维码)。

活动需要动画化。

我的问题:当代码完全在我的手机上运行时,如何创建此活动?通知仅引用本地类。这是如何运作的? Activity 类会上传到 Wear 设备吗?我可以在多大程度上为活动设置动画?我可以使用设备的 API 吗?

我不确定它应该如何运作。

【问题讨论】:

  • 你找到解决方案了吗?

标签: android android-layout android-activity android-notifications wear-os


【解决方案1】:

为可穿戴设备创建应用程序。 http://developer.android.com/training/wearables/apps/index.html

【讨论】:

  • 是的,这是我的另一个选择。但我不知道当用户与交互时如何启动应用程序
  • 您的评论被截断了。您到底需要什么帮助?
  • 该死的,它应该以“通知”结尾。当用户向左滑动时,我不知道如何打开应用程序。该屏幕通常会显示操作按钮或自定义活动——它们是有限的,因为它们在手机上运行并且基本上可以是图像,如果我没记错的话。我目前通过 contentAction 按钮启动应用程序,但我想在用户滑动时启动它。
【解决方案2】:

通知中的全屏图像不是通过活动完成的,而是添加到通知中的page

NotificationCompat.Builder builder; // Your notification

Bitmap photo; // Your photo to show full screen
Notification photoPage = new NotificationCompat.Builder(mContext)
    .setStyle(new NotificationCompat.BigPictureStyle()
        .bigPicture(photo))
    .extend(new NotificationCompat.WearableExtender()
        .setHintShowBackgroundOnly(true)) // show full screen
    .build();

NotificationCompat.WearableExtender wearableExtender =
    new NotificationCompat.WearableExtender();
wearableExtender.addPage(photoPage);

builder.extend(wearableExtender);

Notification notification = builder.build(); // Notification with image page

【讨论】:

  • 关键点:活动必须是动画的。基本上我需要一个画布。
  • 您不能从通知中制作动画 - 它们是静态的。充其量你的通知可以有一个动作,将你带到可穿戴应用程序中的一个活动,但这听起来也不完全是你想要的
  • @ianhanniballae 好的,这是有道理的。另外,打开一个新活动是一个完全可以接受的解决方案,但我不知道如何实现它?如何在属于移动设备的代码中引用穿戴设备中的 Activity 类?
【解决方案3】:

您需要使用例如从您的移动应用程序触发您的穿戴应用程序的消息 (MessageApi)。您还可以监听数据变化 (DataApi)。

评论更新:

创建 WearableListenerService 的子类并监听消息或数据 API 的变化,我推荐消息 API:

public class SomeService extends WearableListenerService {
    @Override
    public void onMessageReceived(MessageEvent messageEvent) {
        super.onMessageReceived(messageEvent);
        Log.d(TAG, "onMessageEvent: " + messageEvent);
        if (messageEvent.getPath().equals("/launchApp")) {
            postNotification();
        }
    }

记得在你的穿戴应用的AndroidManifest.xml中声明正确的intent filter:

    <service
        android:name=".SomeService"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
        </intent-filter>
    </service>

【讨论】:

  • 谢谢。如果你不介意,你能告诉我应该监听数据变化的服务是如何启动的吗?我应该如何测试它?我当前的设置是物理 S3 和虚拟 Wear 设备。
  • 我建议您创建一个WearableListenerService 并覆盖public void onDataChanged(DataEventBuffer events)public void onMessageReceived(MessageEvent)。您还需要在 Wear 应用的 AndroidManifest.xml 中为您的服务声明一个意图过滤器。操作为com.google.android.gms.wearable.BIND_LISTENER,您的服务需要标记为android:exported="true"
  • 我在from this answer 的帮助下找到了答案。你的评论基本上是在暗示同样的事情。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多