intent://scan/#Intent;scheme=appname://appname/【频道】/【id】;package=com.appname.package;end

http://m.chuanbang.com/wear/12969

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

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

这一句就可以了。

各个项目含义如下所示:

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

host:适当记述

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

query:获取值的Key和Value  ※没有也可以

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

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

接下来是Android端。

首先在AndroidManifest.xml的MAIN 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 …/>。

其中必须的内容仅scheme,没有其他内容app也能启动。

※注意事项: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>

复制代码

这样的话,没有问题。

接下来在Activity中需要取值的地方添加以下代码,我是直接写在OnCreate函数里的:

Intent i_getvalue = getIntent();

String action = i_getvalue.getAction();

if(Intent.ACTION_VIEW.equals(action)){

Uri uri = i_getvalue.getData();

if(uri != null){

String name = uri.getQueryParameter("name");

String age= uri.getQueryParameter("age");

}

}

这样就能获取到URL传递过来的值了。

——————————————————————————————————我是分割线————————————————————————————————————

代码copy完了,是不是很惊奇的发现用浏览器输入

myapp://jp.app/openwith?name=zhangsan&age=26

是不是404,打不开?

楼主你这不是骗人么!楼主你个混蛋啊。

客官,稍安勿躁啊,你看看你用的浏览器是什么?UC,猎豹,欧朋?放弃吧,试试系统自带浏览器或者谷歌浏览器吧。肯定能成功的,不能成功的话再来坑我。哈哈。

——————————————————————————————————我是分割线————————————————————————————————————

突然觉得好悲哀,好不容易get了这个技能,却不能被第三方浏览器使用。在这个android浏览器大部分被第三方占据着的时代不得不说是个悲剧啊。

接下来还是说说为什么第三方浏览器不能成功吧。首先,我发现的是UC浏览器,如果你使用了自己的scheme,而不是http的话,uc会默认在你的scheme前面添加http://。这太坑爹了。其他浏览器没看是不是同样的情况。发现这个问题后我就试着把自己的scheme换成http。然后满怀期待的又跑了一遍,结果还是坑爹了。所以我想会不会是第三方浏览器对url做了处理。到这里,我也无可奈何了。我测试了UC,猎豹,欧朋,这3个都不支持。系统自带的和谷歌浏览器是支持的。

最后再补充个线索吧,在浏览器里搜索百度应用。进了他们的页面后,他们是可以实现在各种浏览器启动已经安装好的本地app的。看到这个后我就看了下他们页面的源码。

在这里他们页面添加了个data-sentintent的标签,看到这里,应该能确定第三方浏览器应该是默认都不支持发intent的,只能自己起一个。根据前端说,这个标签应该是自定义的。我们前端看源码的时候发现是这样的

所以最后的结果应该是百度这边是起了个端口,然后在应用里启用了一个服务,来监听这个端口,来获取这个intent。大概就这个思路了。不过楼主没有实际去操作。项目时间紧,太麻烦了。

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Use an <intent-filter> with a <data> element. For example, to handle all links to twitter.com, you'd put this inside your <activity> in your AndroidManifest.xml:

<intent-filter>
<data android:scheme="http" android:host="twitter.com"/>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then, when the user clicks on a link to twitter in the browser, they will be asked what application to use in order to complete the action: the browser or your application. Of course, if you want to provide tight integration between your website and your app, you can define your own scheme: <intent-filter>
<data android:scheme="my.special.scheme" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
Then, in your web app you can put links like: <a href="my.special.scheme://other/parameters/here">
And when the user clicks it, your app will be launched automatically (because it will probably be the only one that can handle my.special.scheme:// type of uris). The only downside to this is that if the user doesn't have the app installed, they'll get a nasty error. And I'm not sure there's any way to check. Edit: To answer your question, you can use getIntent().getData() which returns a Uri object. You can then use Uri.* methods to extract the data you need. For example, let's say the user clicked on a link to http://twitter.com/status/1234: Uri data = getIntent().getData();
String scheme = data.getScheme(); // "http"
String host = data.getHost(); // "twitter.com"
List<String> params = data.getPathSegments();
String first = params.get(0); // "status"
String second = params.get(1); // "1234"
You can do the above anywhere in your Activity, but you're probably going to want to do it in onCreate(). You can also use params.size() to get the number of path segments in the Uri. Look to javadoc or the android developer website for other Uri methods you can use to extract specific parts.
function open_scheme_in_app(){
var url=window.location.pathname;
var data=url.split("/");
var name=data[1];
var id=data[2];
var isIOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent);
var wechat = /MicroMessenger/i.test(navigator.userAgent);
if(wechat){
if(isIOS){
$$('shadow').style.display='block';
}else{
window.location='http://a.app.qq.com/o/simple.jsp?pkgname=com.dotfive.chuanbang&g_f=991653'
}
}else if(isIOS) {
setTimeout(function () {
window.location='http://itunes.apple.com/cn/app/id898162055?mt=8';
},2000);
window.location = 'chuanbang://?'+name+'&'+id;
}else{
window.location='intent://scan/#Intent;scheme=chuanbang://cbapp/'+name+'/'+id+';package=com.dotfive.chuanbang;end';
}
}

怎么在android实现通过浏览器点击链接打开apk的更多相关文章

  1. android实现通过浏览器点击链接打开本地应用(APP)并拿到浏览器传递的数据

    为了实现这个功能可折腾了我好久,先上一份代码,经楼主验证是绝对可以用的而且也比较清晰的代码!(ps:还是先剧透下吧,第三方大部分浏览器无法成功.) 点击浏览器中的URL链接,启动特定的App. 首先做 ...

  2. android--实现通过点击链接打开apk(应用图标在桌面消失)

    首先在AndroidManifest.xml的MAIN Activity下追加以下内容.(启动Activity时给予) ※必须添加项 <intent-filter> <action ...

  3. Android编程实现点击链接打开APP功能示例

    本文实例讲述了Android编程实现点击链接打开APP功能.分享给大家供大家参考,具体如下: 在Android中点击链接打开APP是一个很常见的需求.例如,电商为用户发送优惠券之后经常会下发一条短信: ...

  4. 在Chrome浏览器中点击链接,打开IE浏览器,跳转到指定页面并传递参数

    需求: 在Chrome浏览器中点击链接,打开IE浏览器,跳转到指定页面并传递参数 过程: 一些应用软件可以通过点击URL链接启动并执行操作(例如迅雷),这是如何做到的呢? 主要是通过修改注册表,注册U ...

  5. Android安装应用后点击&quot;打开&quot;(Open)带来的问题及解决方案

    MainActivity例如以下: package cc.cc; import android.app.Activity; import android.content.Intent; import ...

  6. 浏览器中点击链接,跳转qq添加好友的实现方式

    做android三年了,都不知道到底干了啥,现在好好研究应该来得及,哈哈哈,希望看到文章的人共勉,哈哈哈(新手写文章,大佬轻喷,呜呜呜~) 好了,这篇只是记录下,项目中遇到的坑(MMP测试),哈哈哈, ...

  7. PC点击链接打开QQ聊天窗口

    <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=QQ号码&site=qq& ...

  8. html点击链接打开新窗口

    html标记中格式为<a href="url"> text </a> 此时,内容在原来窗口呈现,如果想新开窗口,可以采用下列方式. 1. <a hre ...

  9. EasyUI_tabs和layout布局, 点击链接打开标签, 重复点击选中标签

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

随机推荐

  1. java web中get请求中文乱码在filter中解决

    之前已经讲过get或者post方法的中文乱码问题,之前都是在每个方法中编写设置编码.如果程序变大,就会很繁琐,使用filter可以避免这种繁琐. 1)写一个encodingFilter进行编码设置 p ...

  2. Windows下搭建HTK

    转自:http://blog.csdn.net/yanli0823/article/details/8186382 亲测有效,环境: windows 8.1 perl版本: HTK版本:Hidden ...

  3. Redis(十五):哨兵Sentinel

    Redis哨兵 Redis 的 Sentinel 系统用于管理多个 Redis 服务器(instance), 该系统执行以下三个任务: 监控(Monitoring): Sentinel 会不断地检查你 ...

  4. 字符串函数---itoa()函数具体解释及实现

    itoa()函数 itoa():char *itoa( int value, char *string,int radix); 原型说明: value:欲转换的数据. string:目标字符串的地址. ...

  5. ubuntu内窗口最大最小化

    我用的dell笔记本,开始的时候,需要修改dell笔记本的BIOS,里面有一个 Funtion Key 一开始定义的行为是多媒体的,需要改成默认行为,具体记不清了, 反正知道这个,肯定知道哪里找. 然 ...

  6. SQL2005数据库行列转换

    注意:列转行的方法可能是我独创的了,呵呵,因为在网上找不到哦,全部是我自己写的,用到了系统的SysColumns (一)行转列的方法 先说说行转列的方法,这个就比较好想了,利用拼sql和case wh ...

  7. atitit.XML类库选型及object 对象bean 跟json转换方案

    atitit.XML类库选型及object 对象bean 跟json转换方案 1. XML类库可以分成2大类.标准的.这些类库通常接口和实现都是分开的 1 2. 常见的xml方面的方法 2 2.1.  ...

  8. atitit.提升研发管理的利器---重型框架 框架 类库的区别

    atitit.提升研发管理的利器---重型框架 框架 类库的区别 1. 重型框架就是it界的重武器. 1 2. 框架 VS. 库 可视化图形化 1 3. 应用框架 1 4. 类库 2 5. 框架是不可 ...

  9. Atitit.软件gui按钮and面板---通讯子系统(区)-- github 的使用....

    Atitit.软件gui按钮and面板---通讯子系统(区)-- github 的使用.... 1. 1.注册账户以及创建仓库 1 2. 二.在GitHub中创建项目(create a new rep ...

  10. UIApplication深入学习

    多时候,我们不需要关心这个类,我们很少继承这个类,偶尔会调用这个类的api来实现一些功能,但是不可否认,这个类是iOS编程中很重要的一个概念.UIApplication的核心作用是提供了iOS程序运行 ...