如何注册一些 URL 命名空间 (myapp://app.start/) 以通过在 Android 操作系统的浏览器中调用 URL 来访问您的程序? [英] How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS?

查看:11
本文介绍了如何注册一些 URL 命名空间 (myapp://app.start/) 以通过在 Android 操作系统的浏览器中调用 URL 来访问您的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想创建一个 Android 应用程序,以便它可以在 android 操作系统中的某个地方注册(或者只是在系统启动时启动),并且当电话用户点击网络浏览器内网页上的特殊按钮时,la:

So I want to create an Android app so it would be registered somewhere in android OS (or just would start on system start) and when phone user clicks on special button on a web page inside a web browser a la:

 <a href="myapp://mysettings">Foo</a> 

我的应用程序将使用该 URL 中发送的参数弹出并运行.

my app would pop up and run using the params sent in that URL.

那么我该怎么做呢?

我需要一个带代码的教程!

I need a tutorial with code!

推荐答案

您需要通过 W3C 等遵循 URI 的标准规则,这基本上意味着:不要这样做.

You need to follow the standard rules for URIs via the W3C and such, which basically means: do not do this.

Android 定义了用于描述通用 Intent 的 Uri 语法.在 Intent 上有一些方法可以与这种表示进行转换,例如:http://developer.android.com/reference/android/content/Intent.html#toUri(int)

Android defines a Uri syntax for describing a generic Intent. There are methods on Intent for converting to and from this representation, such as: http://developer.android.com/reference/android/content/Intent.html#toUri(int)

因此,这样做的方法是使用常规工具在清单中描述您将使用特定组件处理的意图类型,尤其是在您自己的命名空间 (com.mycompany.myapp.action.DO_SOMETHING 或其他).然后,您可以创建一个与您的组件匹配的 Intent,并使用 Intent.toUri() 来获取它的 URI 表示.这可以放置在您的链接中,然后在按下时查找可以处理的内容,从而找到您的应用程序.注意要像这样从浏览器启动,组件必须处理 BROWSABLE 类别.(你不需要在你放在链接中的 Intent 中有这个,浏览器会自动为你添加这个.)

So the way to do this is to use the normal facilities to describe an in your manifest for the kinds of intents you are going to handle with a particular component, especially defining an action name in your own namespace (com.mycompany.myapp.action.DO_SOMETHING or whatever). You can then make an Intent that matches your component, and use Intent.toUri() to get the URI representation of this. This can be placed in your link, and will then when pressed look for something that handles and and thus find your app. Note to be launched from the browser like this, the component's must handle the BROWSABLE category. (You don't need to have this in the Intent you put in the link, the browser will automatically add this in for you.)

最后,您可能希望将意图的包设置为您的应用程序:http://developer.android.com/reference/android/content/Intent.html#setPackage(java.lang.String)

Finally, you may want to set the package of the intent to your app with this: http://developer.android.com/reference/android/content/Intent.html#setPackage(java.lang.String)

这是平台中较新的功能,它允许您将意图链接到仅您的应用程序,以便其他应用程序无法拦截和处理它们.

This is a newer feature in the platform, which allows you to direct link intents to only your app so that other applications can not intercept and handle them.

总而言之:阅读有关意图和意图过滤器的常规文档(例如 NotePad 教程,尽管您不会在这里使用内容:URI,可能只是自定义操作)并使您的应用程序以这种方式工作.然后您可以创建一个浏览器链接以相同的方式启动您的应用,前提是您的意图过滤器处理 BROWSABLE 类别.

In summary: read the regular documentation on intents and intent filters (such as the NotePad tutorial, though you won't be using content: URIs here, probably just custom actions) and get your app working that way. Then you can make a browser link to launch your app in the same way, provided your intent-filter handles the BROWSABLE category.

这篇关于如何注册一些 URL 命名空间 (myapp://app.start/) 以通过在 Android 操作系统的浏览器中调用 URL 来访问您的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆