无法导入com.google.android.wearable.intent.RemoteIntent for Wear



我正试图在Wear OS应用程序上实现"打开手机"按钮,但无法导入RemoteIntent类。

当我添加导入com.google.android.wearable.intent.RemoteIntent到我的MainActivity.java时,可穿戴设备以红色下划线显示"无法解决符号"错误。

我是否需要在我的项目中添加一个特定的依赖项以使其可用?

RemoteIntent的文档没有给我任何线索,我可能错过了什么。

对于上下文,我试图在我的应用程序中使用以下代码片段:

private void openOnPhone(Uri uri) {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
RemoteIntent.startRemoteActivity(this, intent, null);
// 'Open on phone' confirmation overlay
new ConfirmationOverlay().setType(ConfirmationOverlay.OPEN_ON_PHONE_ANIMATION).setMessage("Opened on phone").showOn(this);
}

您需要导入:

androidx.wear:wear-remote-interactions:1.0.0

然后使用以下语句:

RemoteActivityHelper(application).startRemoteActivity(
Intent(Intent.ACTION_VIEW).apply {
addCategory(Intent.CATEGORY_DEFAULT)
.addCategory(Intent.CATEGORY_BROWSABLE)
data = Uri.parse("some://uri")
},
null
)

然而,这个库确实需要compileSdkVersion 31 (Android 12)

我认为您需要添加以下一个或两个依赖项:

androidx.wear:wear-phone-interactions:1.0.0-beta01
androidx.wear:wear-remote-interactions:1.0.0-beta01

在这里的发布说明中有提到。还有一个关于重命名的注意事项,可能与您相关:

我们添加了RemoteIntentHelper类(之前的RemoteIntent)可穿戴支撑库),可用于打开意图其他设备(例如从手表到手机)。(I1d7e0)

此包:

implementation 'com.google.android.support:wearable:2.8.1'

最新更新