我正在开发需要自定义 URL 方案的应用,看起来像“appname://”
我搜索了很多东西,也找到了很多相关的问题,但我仍然遇到问题。
如何从浏览器测试这个 URL Scheme?目前,每当我在浏览器的地址栏中输入“appname://”时,它都会直接进入 Google 搜索。
我的 AndroidManifest.xml 中有这个:
<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="appname"
android:host="appnamehost"/>
</intent-filter>
最佳答案
通过 adb 很容易。检查此命令:
adb shell am start -a android.intent.action.VIEW -d "appname://appnamehost" your.package.name
但是,您应该使用您的包名作为架构。因此,您可以绝对确定没有冲突(或者详细地说是 Intent 选择器)。
如果您有多个设备,则需要执行 adb devices
。这将产生如下输出:
List of devices attached
1645e1d0b86b device
S9WM00904386 device
然后您可以使用上面的 id 通过 -s
参数来寻址具体设备。这将产生如下命令行:
adb -s S9WM00904386 shell [...]
如果是浏览器链接,这也很容易。你只需要添加这行html:
<a href="appname://appnamehost">Click me</a>
如果你想在你的 url 中使用后备,你可以试试 Intent url:
<a href="intent://apphostname#Intent;scheme=appname;package=your.package.name;S.browser_fallback_url=http%3A%2F%2Fwww.example.com;end">with alternative</a>
即使您的架构不是唯一的,这也会打开您的应用,如果您的应用未安装,它将打开 example.com。
关于android - 如何在android中测试自定义URL方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31876003/