简体   繁体   中英

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. 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 . In the wear part of the project, there is another activity called 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:

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)

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?

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. The wear app can then locally launch its own notification which includes the WearActivity action.

This is documented in https://developer.android.com/training/wearables/data-layer/messages.html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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