简体   繁体   English

如何在手表上远程从手机打开 Google Play(Wear OS)

[英]How to open Google Play from the phone remotely on the watch (Wear OS)

What is the correct way to remotely open Google Play from the phone on the watch (Wear OS)?在手表(Wear OS)上从手机远程打开 Google Play 的正确方法是什么? I am trying this:我正在尝试这个:

Intent intentOnWatch = new Intent(Intent.ACTION_VIEW)
        .addCategory(Intent.CATEGORY_BROWSABLE)
        .setData(Uri.parse("https://play.google.com/store/apps/details?id=\" + getPackageName()"));

RemoteIntent.startRemoteActivity(getApplicationContext(), intentOnWatch, null, null);

But nothing happens.但什么也没有发生。

The last parameter is the nodeId.最后一个参数是nodeId。 I left it as zero because the documentation says:我将其保留为零,因为文档说:

nodeId String: Wear OS node id for the device where the activity should be started. nodeId String:应启动 Activity 的设备的 Wear OS 节点 ID。 If null, and the current device is a watch, the activity will start on the companion phone device.如果 null,并且当前设备是手表,则活动将在配套手机设备上启动。 Otherwise, the activity will start on all connected watch devices.否则,活动将在所有连接的手表设备上启动。

Source: https://developer.android.com/reference/com/google/android/wearable/intent/RemoteIntent#startremoteactivity资料来源: https://developer.android.com/reference/com/google/android/wearable/intent/RemoteIntent#startremoteactivity

I could determine the nodeId, but it seems difficult to do.我可以确定nodeId,但似乎很难做到。 Plus in this case, starting the activity on all connected watch devices would be fine.另外在这种情况下,在所有连接的手表设备上启动活动就可以了。

This example (sorry it's Kotlin) should work这个例子(对不起,它是 Kotlin)应该可以工作


            val remoteActivityHelper =
                RemoteActivityHelper(application, Dispatchers.IO.asExecutor())

            val nodes = Wearable.getNodeClient(application).connectedNodes.await()
            val nodeId = nodes.firstOrNull { it.displayName == "XXX" }?.id

            if (nodeId == null) {
                Toast.makeText(application, "No connected wear watch", Toast.LENGTH_SHORT).show()
            } else {
                try {
                    remoteActivityHelper.startRemoteActivity(
                        Intent(Intent.ACTION_VIEW)
                            .addCategory(Intent.CATEGORY_BROWSABLE)
                            .setData(
                                Uri.parse("https://www.bbc.co.uk/sounds/play/${programme.code}")
                            ),
                    ).await()
                } catch (e: Exception) {
                    toaster.showToast("Unable to open mobile app: ${e.message}")
                }
            }
        }

But the main thing in your example is that you are not checking the result of startRemoteActivity, it returns a ListenableFuture, so you could check for an error.但是您示例中的主要内容是您没有检查 startRemoteActivity 的结果,它返回一个 ListenableFuture,因此您可以检查错误。 In the example above, I'm using the.await() extension function which does the same thing.在上面的例子中,我使用了 .await() 扩展 function 来做同样的事情。

There are more complete examples in https://github.com/android/wear-os-samples/blob/d18c489ff415aa0fbb25c260e3aacdf50f7716e3/WearVerifyRemoteApp/Application/src/main/java/com/example/android/wearable/wear/wearverifyremoteapp/MainMobileActivity.kt https中有更完整的例子://github.com/android/wear-os-samples/blob/d18c489ff415aa0fbb25c260e3aacdf50f7716e3/WearVerifyRemoteApp/Application/src/main/java/com/example/android/wearable/wear/wearverifyremo.app吨

I've been fighting with exatly the same problem last two days.过去两天我一直在与同样的问题作斗争。 Works for me the next code:下一个代码对我有用:


    Intent intent = new Intent(Intent.ACTION_VIEW)
        .addCategory(Intent.CATEGORY_BROWSABLE)
        .setData(Uri.parse(PLAY_STORE_APP_URI));

    for (Node node : nodesWithoutApp) {
        RemoteActivityHelper remoteActivityHelper = 
            new RemoteActivityHelper(this, Executors.newSingleThreadExecutor());
        remoteActivityHelper.startRemoteActivity(intent, node.getId());
    }

It didn't work with RemoteIntent.startRemoteActivity for some reason.由于某种原因,它不适用于 RemoteIntent.startRemoteActivity。

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

相关问题 如何在 Wear OS 模拟器上打开表盘列表? - How do I open the watch faces list on the Wear OS emulator? 如何从手机/手机传递一些信息来佩戴操作系统并在 android 佩戴操作系统模拟器中显示? - How to pass some information from mobile/phone to wear os and display it in android wear os emulator? Google Play 拒绝我的 Wear os 配套应用,在手机上启动时崩溃 - Google Play reject my wear os companion app with crashed when launch on phone 我们的 Wear OS 应用未在 Google Play 中列出 - Our Wear OS app not listed on the Google Play Android Wear - 在手机上启动Google Play - Android Wear - Launching Google Play on Phone 使用 Google fit 从配对的应用程序中读取 Wear os 手表的心率 - Reading the Heart Rate from wear os watch using Google fit from a paired app 如何从电话创建的通知中打开磨损活动 - How to open a Wear Activity from a Notification created by Phone Wear os build 内部测试被 Google Play 商店拒绝 - Wear os build internal testing got rejected from google play store Android Wear 2.0通过手机获取位置,并在Google Play商店中支持设备支持 - Android Wear 2.0 getting location from phone and keeping device supported on Google Play store 通过蓝牙将数据从Andread Wear Watch传输到手机 - Data Transfer from Andread Wear Watch to phone via bluetooth
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM