gpt4 book ai didi

java - Android Wear Intent 过滤器

转载 作者:太空宇宙 更新时间:2023-11-04 13:53:45 25 4
gpt4 key购买 nike

我正在尝试使用自定义 Intent 过滤器来调用 Android Wear Activity 。 (不确定这是最好的主意吗?)但是,在穿戴应用程序上注册 Intent 过滤器并部署移动应用程序后,我收到错误:

Applications have the same package name com.nybblemouse.datalayerdatamap:
mobile, wear

有人可以提供一些建议吗?

背景信息:

我正在开发一个 Android Wear 应用程序,该应用程序使用数据层 API 来允许 http 连接访问简单的 API 并在 watch 应用程序上显示响应。

我已经使用数据层 API 成功要求移动应用进行调用,现在想要调用 watch 上的 Activity 以显示结果。

Android Wear list :

  <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.nybblemouse.datalayerdatamap.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name=".ListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER" />
</intent-filter>
</service>
</application>

在我单独的监听器服务类(用于数据层 API)中,成功的 http 响应后:

Intent chilliIntent = new Intent();
chilliIntent.setAction("com.nybblemouse.datalayerdatamap.MainActivity");
chilliIntent.putExtra("CHILLIS", "10");
startActivity(chilliIntent);

最佳答案

经过一些广泛的研究,我创建了一个示例 Android Studio 项目,演示了如何实现这一点。简而言之,所有网络流量都需要经过Android Wear API,即Message API或Data Layer API。据传,这一情况将在即将于 2015 年 5 月 27 日举行的 Google IO Activity 中发生变化,并支持 Wear 设备上的 native WiFi。

从移动设备调用 Wea​​r 设备上的 Activity 的过程如下(假设您选择了数据层 API):

  1. 创建 Intent 中发送所需数据的数据映射。
  2. 使用适当的回调创建新的数据层 API 对象
  3. 使用 Node API,循环浏览节点或使用数据层 API 发送器方法广播到您选择的节点。
  4. 在穿戴式设备上,使用所需的回调实现服务数据层 API 类
  5. 使用 OnDataChanged 回调,监听您的发送数据映射,并根据需要提取数据
  6. 照常使用 Intent 从 OnDataChanged 方法启动 Activity 。

我已经用 DFD、幻灯片和示例项目详细记录了这一点。您可以在我的 Github 项目上查看全部内容:

https://github.com/kirgy/fandos

该项目于 2015 年 5 月提交给英国布里斯托尔的 South West Mobile 用户组: http://www.meetup.com/swmobile/events/220749834/

关于java - Android Wear Intent 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30039903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com