Android 如何在adb shell am start的URL中包含符号?
使用 我可以使用活动管理器启动URL。但是,如果我包含多个URL参数,则除第一个参数外,其他所有参数都会被剥离 例如:Android 如何在adb shell am start的URL中包含符号?,android,adb,Android,Adb,使用 我可以使用活动管理器启动URL。但是,如果我包含多个URL参数,则除第一个参数外,其他所有参数都会被剥离 例如: $ adb shell am start some://url 返回: $ adb shell am start http://www.example.com?param1=1¶m2=2 当一个符号被忽略后,param2就消失了。我想知道是否有一些编码/转义字符可以防止这种情况。使用转义字符\: $ Starting: Intent { act=androi
$ adb shell am start some://url
返回:
$ adb shell am start http://www.example.com?param1=1¶m2=2
当一个符号被忽略后,param2就消失了。我想知道是否有一些编码/转义字符可以防止这种情况。使用转义字符
\
:
$ Starting: Intent { act=android.intent.action.VIEW dat=http://www.example.com?param1=1 }
我已经在这里发布了一个解决方法: 因此,这里是涉及仪器的配方。
在侦听action com.example.action.VIEW的检测中注册BroadcastReceiver
$ adb shell am start "http://www.example.com?param1=1\¶m2=2"
将符号替换为%26(use可以将其替换为您想要的任何内容),并发送一个intent com.example.action.VIEW。一旦接收到意图广播接收器,它会将%26转换回与符号,并向您的应用程序发送带有所需操作的新意图
IntentFilter intentFilter = new IntentFilter("com.example.action.VIEW");
intentFilter.addDataScheme("myschema");
intentFilter.addCategory(Intent.CATEGORY_BROWSABLE);
Context.registerReceiver(new MyBroadcastReceiver(), intentFilter);
基本上,它充当一个BroadcastReceiver代理。由于android构建工具中的一个缺陷,接受的解决方案无法工作,您可以在此处跟踪该缺陷:。解决方法如下所示:
public final void onReceive(final Context context, final Intent intent) {
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(intent.getDataString().replaceAll("%26", "&")));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
引用
am…
命令类似于以下内容的内容应该有效(如果不行,请尝试双引号):
以下格式似乎有效。请注意引号格式
”
“
:
$adb外壳am开始-d'”http://www.example.com?param1=1¶m2=2“
不幸的是,对于平台工具版本21,存在一个错误,即URL在第一个符号AND之后会被截断,即使您将其转义。请查看此问题解决方法是发送:$adb shell am start”http://www.example.com?param1=1%26param2=2“
谢谢!这是现在测试INSTALL\u Referer广播的正确方法。我想知道这是否应该是公认的答案,因为它似乎比必须在已构建的链接中逃逸每一个符号要好得多。
echo 'am broadcast -a com.android.vending.INSTALL_REFERRER -n <your package>/<broadcast-receiver> --es "referrer" "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name";exit'|adb shell
commandLine "bash","-c","echo ..."
adb shell 'am start http://www.example.com?param1=1¶m2=2'