如何当点击浏览器的URL打开Android应用程序 [英] How to open android application when an URL is clicked in the browser

查看:251
本文介绍了如何当点击浏览器的URL打开Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要打开我的Andr​​oid应用程序,当用户点击了我的域名中的链接。例如,可以说我的域名abc.com,我已经张贴了我的Facebook页面上此链接。当我的一个朋友(谁我的应用程序安装在自己的设备)点击链接(在设备的浏览器)上,我应该能够在我的应用程序中的网页视图中打开我的网站。

I have to open my android application, when user clicks on a link that has my domain name. For example, lets say my domain is abc.com and i have posted this link on my Facebook page. When one of my friend(who has my application installed in his device) clicks on the link(in the device's browser), i should be able to open my website in a webview inside my application.

我不知道如何得到这个工作,但是会意向过滤器的工作?如果是这样,有人可以给我一张code的开始吗?

I am not sure how to get this work, but will intent-filters work? If so, can someone give me a piece of code to start with?

推荐答案

您必须定义在点击URL时,应该推出的活动定制的意图过滤器。

You have to define a custom Intent Filter in the activity that should be launched when the url is clicked.

让说,要启动FirstActivity当用户点击 http://www.example.com/ 网页上的链接。

Let say that you want to launch the FirstActivity when a user click a http://www.example.com/ link on a web page.

在清单添加到您的活动:

Add this to your activity in the Manifest :

<activity android:name=".FirstActivity"
          android:label="FirstActivity">
  <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="www.example.com" android:scheme="http"></data>
  </intent-filter>
</activity>

当用户将点击HTML链接 http://www.example.com/~~V 中,系统会提示或者使用浏览器或您的应用程序。

When the user will click a HTML link to http://www.example.com/, the system will prompt either to use the browser or your app.

这篇关于如何当点击浏览器的URL打开Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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