【问题标题】:Android - start an activity from command line using intent uriAndroid - 使用意图 uri 从命令行启动活动
【发布时间】:2014-01-28 19:51:05
【问题描述】:

我有一个带有以下意图过滤器的活动 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>

我基本上是在按照here 解释的那样在意图过滤器中尝试自定义数据方案

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

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

我收到以下错误:

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

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

here 提供了使用 adb 命令使用 Intent uri 启动活动的说明。

【问题讨论】:

  • adb shell 'am start "intent:////show/#Intent;scheme=customapp;package=com.comp.pac;end"' 它将解决您的问题它将启动您的活动

标签: android android-intent adb intentfilter url-scheme


【解决方案1】:

你需要使用"":

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      从 shell 运行 Activity 的另一种方式:

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

      注意package 名称后面的“/”和“.”。在Activity 名称之前。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多