Android 使用 RemoteActivityHelper 从手表启动手机中的应用程序

问题描述 投票:0回答:1

这是使用 RemoteActivityHelper 在具有特定应用程序 ID 的连接设备(智能手表或手机)中打开 Play 商店的代码示例,现在我确定该应用程序已安装在其他设备上,我只想启动它,我怎么能做到呢?

val remoteActivityHelper = RemoteActivityHelper(context, executor)

val result = remoteActivityHelper.startRemoteActivity(
    Intent(Intent.ACTION_VIEW)
        .setData(
            Uri.parse("http://play.google.com/store/apps/details?id=com.example.myapp"))
        .addCategory(Intent.CATEGORY_BROWSABLE),
    nodeI
android android-studio
1个回答
0
投票

startRemoteActivity
支持将操作设置为
ACTION_VIEW
的意图。 目标应用程序必须有一个处理
"android.intent.action.VIEW"
:

的 Activity
<activity android:name=".TargetActivity" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="https"
              android:host="www.myaddress.com" />
    </intent-filter>
</activity>

然后,您可以使用以下方式开始此活动:

val remoteActivityHelper = RemoteActivityHelper(context, executor)

val result = remoteActivityHelper.startRemoteActivity(
    Intent(Intent.ACTION_VIEW)
        .setData(
            Uri.parse("https://www.myaddress.com"))
        .addCategory(Intent.CATEGORY_BROWSABLE),
    nodeId)
© www.soinside.com 2019 - 2024. All rights reserved.