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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21034168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:52:57  来源:igfitidea点击:

Android - start an activity from command line using intent uri

androidandroid-intentadbintentfilterurl-scheme

提问by 500865

I have an Activity A with the following intent filter

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

I am basically trying the custom data scheme in intent filters as explained here

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

To test whether the IntentUri launches the activity or not I'm trying to fire the intent using the following command through terminal :

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

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

I get the following error :

我收到以下错误:

Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=intent://show/ flg=0x10000000 }

Question : Is there anything wrong with the command? If not, what is the easiest way to test whether the intent uri starts the activity?

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

The instructions for using the adbcommand to start activity using intent uri is available here.

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

回答by Alex P.

You need to use "":

您需要使用""

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

回答by Hendrix

Another way to run an Activity from the shell:

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

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

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

Note the "/" after the packagename and the "." before the Activityname.

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

回答by manmohan

Another way to open activity :

另一种打开活动的方式:

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

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