您需要通过 W3C 等遵循 URI 的标准规则,这基本上意味着:不要这样做。
Android 定义了用于描述通用 Intent 的 Uri 语法。 Intent 上有一些方法可以与这种表示进行相互转换,例如:http://developer.android.com/reference/android/content/Intent.html#toUri(int)
因此,这样做的方法是使用常规工具在清单中描述您将使用特定组件处理的各种意图,尤其是在您自己的命名空间(com.mycompany. myapp.action.DO_SOMETHING 或其他)。然后,您可以创建一个与您的组件匹配的 Intent,并使用 Intent.toUri() 来获取它的 URI 表示。这可以放置在您的链接中,然后在按下时会查找可以处理的内容,从而找到您的应用程序。注意要像这样从浏览器启动,组件必须处理 BROWSABLE 类别。 (你不需要在你放入链接的 Intent 中有这个,浏览器会自动为你添加这个。)
最后,您可能希望将 Intent 的包设置为您的应用:http://developer.android.com/reference/android/content/Intent.html#setPackage(java.lang.String)
这是平台中的一项较新功能,它允许您将意图链接到仅您的应用程序,以便其他应用程序无法拦截和处理它们。
总结:阅读有关意图和意图过滤器的常规文档(例如 NotePad 教程,尽管您不会在这里使用 content: URI,可能只是自定义操作)并让您的应用程序以这种方式运行。然后,您可以创建一个浏览器链接,以同样的方式启动您的应用,前提是您的意图过滤器处理 BROWSABLE 类别。
<activity android:name=".MyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:host="my.app" android:scheme="http"></data>
</intent-filter>
</activity>
然后,http://my.app 应该启动您的活动。
source
source