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

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

问题描述

所以,我想,当手机用户点击特殊的按钮在网页上的内部Web浏览器一拉来创建一个Android应用程序,所以它会在某处Android操作系统进行登记(或只是将开始在系统启动时)和

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发送PARAMS。

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

所以,我该怎么做这样的事情?

So how do I do such thing?

我需要code教程!

推荐答案

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

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

安卓定义的URI语法描述一个通用的意图。上有意向的方法,用于把去往和来自该再presentation,如:<一href="http://developer.android.com/reference/android/content/Intent.html#toUri%28int%29">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.toUri()来获得这个URI重新presentation。这可以被放置在你的链接,然后会在$ P $寻找pssed的东西,处理和,从而找到你的应用程序。注意从这样的浏览器中启动,组件必须处理可浏览的类别。 (你并不需要有这样的你把链接的意图,浏览器会自动添加此为你。)

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.)

最后,你可能想的意图的包装设置与此您的应用程序:<一href="http://developer.android.com/reference/android/content/Intent.html#setPackage%28java.lang.String%29">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.

在总结:阅读的目的和意图过滤器的常规文件(如记事本教程,虽然你不会使用的内容:这里的URI,可能只是自定义操作),让您的应用程序工作的方式。然后,你可以做一个浏览器链接,启动以同样的方式您的应用程序,只要你的意图过滤处理可浏览的类别。

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/)通过调用浏览器的URL在Android操作系统访问你的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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