浏览器点击链接启动安卓APP

2 篇文章 0 订阅
1 篇文章 0 订阅

最近来了个需求,需要在浏览器中点击一个链接.如果用户没有安装APP,跳转到下载页面.如果用户已经安装APP则直接启动APP. 这个需求的难点在于如何在浏览器中启动APP.


网上有资料来讨论这个问题, 相信大家会很容易找到. 基本思路是这样的:

点击浏览器中的URL链接,启动特定的App

首先做成HTML的页面,页面内容格式如下:

<a href="[scheme]://[host]/[path]?[query]">启动应用程序</a> 

这一句就可以了。

 

各个项目含义如下所示:

scheme:判别启动的App详细后述

host:适当记述

path:传值时必须的key     ※没有也可以

query:获取值的KeyValue  ※没有也可以

 

作为测试好好写了一下,如下:

<a href="myapp://jp.app/openwith?name=zhangsan&age=26">启动应用程序</a>  

接下来是Android端。
首先在AndroidManifest.xmlMAIN Activity下追加以下内容。(启动Activity时给予)

必须添加项

<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="myapp" android:host="jp.app" android:pathPrefix="/openwith"/>  </intent-filter>


HTML记述的内容加入<data …/>

本来是很好的方法,结果使用后发现启动不了应用.

 

从我个人的使用经验来说,主要注意以下两个方面:

1.intent-filter的内容【android.intent.action.MAIN】和 【android.intent.category.LAUNCHER】这2个,不能与这次追加的内容混合。
  所以,如果加入了同一个Activity,请按以下这样做,否则会导致应用图标在桌面消失等问题。


<intent-filter>  
    <action android:name="android.intent.action.MAIN"/>  
    <category android:name="android.intent.category.LAUNCHER" />  </intent-filter>  <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="myapp" android:host="jp.app" android:pathPrefix="/openwith"/>  </intent-filter> 

 

这样的话,没有问题。

2. 需要在Manifest文件里边再加入一行代码

<intent-filter>  
    <action android:name="android.intent.action.MAIN"/>  
    <category android:name="android.intent.category.LAUNCHER" />  </intent-filter>  <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="myapp" android:host="jp.app" android:pathPrefix="/openwith"/> 
<data android:scheme="http" android:host="jp.app" android:pathPrefix="/openwith"/>
 </intent-filter> 

因为浏览器对于所有的跳转链接会加上http.

 

注意以上两个方面就可以启动app. 传递参数也非常简单就不再在此啰嗦了.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
*** 用途 *** * 刷网站流量、用户点击量、快速连续点击 * 适用于各类需要代替手工点击的场合 *** 软件特征 *** * 支持最小化后台运行 * IE9内核支持 * 支持代理IP(仅通用版付费用户赠送免费代理ip采集工具) * 支持ADSL自动拨号 * 允许用户设定浏览重置次数 * 支持cookie自动清理 * 随机UserAgent,可模拟chrome浏览器、手机页面 * 支持Flash页面 * 支持网页多点滚动点击 * 支持打开(搜索)指定网页后,进行二次点击 * 支持动作间隔范围设定,运行时随机取时间间隔 * 支持弹出页面二次点击 * 支持加载页面后,连续多点持续点击 * 支持完成任务后自动退出程序 * 支持自动开始执行动作 * 支持隐藏运行 * 支持网址模糊匹配点击 * 支持iframe内链接点击 *** 使用说明 *** 1、下载后,直接运行 webclick.exe 2、在左侧栏设定运行参数 3、单击“开始”按钮。 坐标点击设定: * 定时刷新、随机浏览不需要设定坐标 * 自动点击坐标设定时,多个坐标之间用“|”符号分隔,参考:http://www.werun.cn|123,122|233,23|... 如何查看坐标: * 输入网址,点击“查看坐标”按钮 * 在右侧网页窗口移动鼠标到要点击的超级链接上,状态栏左下角会提示坐标信息 * 注意查看坐标时,不要改变网页窗口的大小! URL模糊点击: * 指点击url包含指定关键字的第一条链接。设定格式参考:http://www.werun.cn|lng_en.htm adsl拨号名如何设定: * 打开网络连接文件夹,获取对应adsl的拨号名。(宽带账户名和密码保存在拨号连接属性里) * 如果拨号名是“网络连接”或“宽带连接”,请改名。比如“adsl123” 持续点击: * 只设置一个网址,后面加多个目标点击坐标 * 间隔时间设定见配置文件项“intervalClickMore”;缺省500毫秒 解释: * 动作次数:每次打开页面、点击页面、关闭;算一次动作;假如有10个网址,动作次数10次,那么每个网址会被点击1次(计算公式:10次动作/10个网址) 注, * 参考时间间隔:要单击的坐标数量 * 单个页面加载的时间。单位:秒 * 用户自定义IP文件名 myip.txt * config.ini文件中设定更多参数 * 免费的代理ip见 代理IP采集工具操作说明 * 一个网址的多个坐标点击也算是一次动作 * 有区域性IP要求的用户,可以提供对在线IP提取系统支持的二次开发。
Android开发中,将浏览器设置为默认浏览器需要以下三个步骤: 1. 在AndroidManifest.xml文件中添加如下代码: ``` <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="http" /> <data android:scheme="https" /> </intent-filter> </activity> ``` 上述代码中,我们设置了MainActivity作为处理在浏览器中打开HTTP或HTTPS链接的Activity。这将把我们的应用程序添加到系统默认浏览器的列表中。 2. 在MainActivity.java文件中添加如下代码: ``` Uri uri = getIntent().getData(); Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri); startActivity(browserIntent); ``` 上述代码中,我们首先获取从浏览器传递的数据,并使用ACTION_VIEW Intent建立一个新的浏览器Intent,最后启动它。 3. 在res文件夹中的layout文件夹中创建一个布局文件,并添加一个使用onClick属性的按钮。在MainActivity.java文件中实现此按钮的点击事件并添加以下代码: ``` PackageManager pm = getPackageManager(); ComponentName componentName = new ComponentName(this, MainActivity.class); pm.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); Intent intent = new Intent(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setData(Uri.parse("http://www.google.com")); startActivity(intent); ``` 上述代码中,我们使用PackageManager和ComponentName类启用我们的主Activity,设置intent的数据来打开特定的网站,并启动新的浏览器Intent。 通过上述三个步骤,我们可以将我们的应用设置为Android系统中默认的浏览器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值