Android - 使用 intent uri 从命令行启动活动



我有一个活动 A,其中包含以下意图过滤器

    <activity
        android:name="com.comp.pac.ActivityA">
        <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="customapp"
                  android:host="show"
                  android:path="/"/>
        </intent-filter>
    </activity>

我基本上是在意图过滤器中尝试自定义数据方案,如此处所述

为了测试IntentUri是否启动活动,我正在尝试通过终端使用以下命令触发意图:

adb shell am start intent://show/#Intent;scheme=customapp;package=com.comp.pac;end

我收到以下错误:

活动未启动,无法解析意向 { act=android.intent.action.VIEW dat=intent://show/flg=0x10000000 }

问:命令有什么问题吗?如果不是,测试意图 uri 是否启动活动的最简单方法是什么?

此处提供了使用 adb 命令通过意向 uri 启动活动的说明。

你需要使用 ""

adb shell 'am start "intent:#Intent;scheme=customapp;package=com.comp.pac;end"'

在此处输入代码另一种打开活动的方法:

$ adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.example.android

从 shell 运行活动的另一种方法:

adb shell am start com.example.hello/.MainActivity

请注意package名称后面的"/"和Activity名称前的"."。

最新更新