android 外部html页面启动本地app及app启动问题
2016-05-16 16:51
555 查看
外部html界面启动本地app
http://my.oschina.net/liucundong/blog/354029?fromerr=KocmE0mO
<pre name="code" class="html"><!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"/> <title>this's a demo</title> <meta id="viewport" name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,minimal-ui"> </head> <body> <div> <a id="J-call-app" href="javascript:;" class="label">立即打开>></a> <input id="J-download-app" type="hidden" name="storeurl" value="http://m.chanyouji.cn/apk/chanyouji-2.2.0.apk"> </div> <script> (function(){ var ua = navigator.userAgent.toLowerCase(); var t; var config = { /*scheme:必须*/ scheme_IOS: 'cundong://', scheme_Adr: 'cundong://splash', download_url: document.getElementById('J-download-app').value, timeout: 600 }; function openclient() { var startTime = Date.now(); var ifr = document.createElement('iframe'); ifr.src = ua.indexOf('os') > 0 ? config.scheme_IOS : config.scheme_Adr; ifr.style.display = 'none'; document.body.appendChild(ifr); var t = setTimeout(function() { var endTime = Date.now(); if (!startTime || endTime - startTime < config.timeout + 200) { window.location = config.download_url; } else { } }, config.timeout); window.onblur = function() { clearTimeout(t); } } window.addEventListener("DOMContentLoaded", function(){ document.getElementById("J-call-app").addEventListener('click',openclient,false); }, false); })() </script> </body> </html>
AndroidMainfext.xml
<activity android:name=".activity.LauncherActivity" android:configChanges="orientation|keyboardHidden|navigation|screenSize" android:label="@string/app_name" android:screenOrientation="portrait" > <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:host="splash" android:scheme="cundong" /> </intent-filter> </activity>
外部html启动本地app之后发现出了问题,如果启动之前那个app已经打开了,那么启动就会导致有些fragment加载不出来了,
后来在启动界面设置启动模式为singleInstance,启动就正常了,但又出现了一个问题,这个启动模式是新创建了一个栈,那么按home键app回到后台后,再点击桌面图标进入app的时候启动界面就跑出来了,然后才显示刚才打开的界面。又百度了一下,发现http://blog.csdn.net/busjb/article/details/40891239</span>
在启动界面添加了代码就正常了
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { //结束你的activity finish(); return; }
但测试的时候又发现了新的问题,app没有启动,在html界面启动,那么按home返回桌面,再在桌面启动,fragment又不显示了,无意中发现手机当前的
应用列表里竟然没有这个app,但这个app分明是运行了,我完全不知道怎么回事。
于是随便搞搞,把启动activity的启动模式设置成singTast 就可以了,虽然我还是不知道为什么
相关文章推荐
- Android实用代码七段(四)
- Android Launcher 自定义View 炫酷换壁纸效果,水瓶加水进度显示效果
- android坐标
- Android中dp和px之间进行转换(工具类)
- Android禁止ViewPager的左右滑动
- Android开发中获取crash信息
- Android编写邮箱之正则表达式
- Android自定义控件2:自定义带下划线的文本或按钮、组合使用可切换tab
- S3c6410 平台 Android系统的Wi-Fi调试记录
- 【Android】18、活动被回收了怎么办
- Android实用代码七段(三)
- Android开发环境搭建
- Androidpn 基于XMPP协议的消息推送实践
- Android 中的接口回调
- Android安全开发之浅谈密钥硬编码
- Android DrawerLayout简单应用
- MonKey:android自动化测试工具
- Android实用代码七段(二)
- android中关于udp发送、接收的一些重点总结
- android对sqlite数据库操作(创建 增 删 改 查)