简体   繁体   English

如何将Android Wear活动类导入移动活动类?

[英]How do I import an Android Wear activity class into a mobile activity class?

I used Android Studio to autogenerate an Android Wear project, which includes a mobile folder for the code that runs on the phone, and a wear folder for the code that runs on the watch. 我使用Android Studio自动生成一个Android Wear项目,该项目包括一个用于在手机上运行的代码的移动文件夹,以及一个用于在手表上运行的代码的wear文件夹。 Both folders contain the same package name hierarchy. 这两个文件夹包含相同的程序包名称层次结构。

In the mobile part of the project, I have an activity called src/main/java/mypackage/MobileActivity.java . 在项目的移动部分,我有一个名为src / main / java / mypackage / MobileActivity.java的活动 In the wear part of the project, there is another activity called src/main/java/mypackage/WearActivity.java . 在项目的损耗部分,还有另一个活动src / main / java / mypackage / WearActivity.java

My problem is, when I try to create a wearable action on the mobile side (according to these instructions ), I can't access the WearActivity class in MobileActivity.java: 我的问题是,当我尝试在移动端创建可穿戴式操作(根据这些说明 )时,无法访问MobileActivity.java中的WearActivity类:

Intent actionIntent = new Intent(this, WearActivity.class);
PendingIntent actionPendingIntent = PendingIntent.getActivity(this, 0, actionIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action wearableAction = new NotificationCompat.Action.Builder(R.drawable.ic_launcher, getString(R.string.label_show_details), actionPendingIntent).build();
new WearableExtender().addAction(wearableAction))

(Error: cannot find symbol class WearActivity) (错误:找不到符号类WearActivity)

So my question is, how should I import WearActivity from the wear side of the project, into the mobile side of the project, so I can refer to it in the Intent I'm creating? 所以我的问题是,我应该如何从项目的损耗侧将WearActivity导入项目的移动侧,以便在创建的Intent中引用它?

The solution is to not reference the WearActivity in the mobile app at all, but instead use com.google.android.gms.wearable.MessageApi to send a message from the mobile app to the wear app. 解决方案是根本不引用移动应用程序中的WearActivity,而是使用com.google.android.gms.wearable.MessageApi将消息从移动应用程序发送到磨损应用程序。 The wear app can then locally launch its own notification which includes the WearActivity action. 然后,wear应用可以在本地启动其自己的通知,其中包括WearActivity操作。

This is documented in https://developer.android.com/training/wearables/data-layer/messages.html . 这在https://developer.android.com/training/wearables/data-layer/messages.html中进行了记录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM