我尝试在 Wear OS 应用上实现“在手机上打开”按钮,但无法导入 RemoteIntent
类。
当我将 import com.google.android.wearable.intent.RemoteIntent
添加到我的 MainActivity.java
时,可穿戴设备将以红色下划线显示,并带有“无法解析符号”错误。
我是否需要向我的项目添加特定的依赖项才能使其可用?
docs对于 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)
关于android - 无法为 Wear OS 应用导入 com.google.android.wearable.intent.RemoteIntent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68816157/