Home > Web Front-end > H5 Tutorial > How to open Android local application - write connection through html5 _html5 tutorial skills

How to open Android local application - write connection through html5 _html5 tutorial skills

WBOY
Release: 2016-05-16 15:51:45
Original
2891 people have browsed it

1. Set link in html

Copy code
The code is as follows:

href=”[scheme]://[host]/[path]?[query]”

The scheme can be set to any value inside the app, and the settings for android and ios are the same
2. If the local application exists, open the app directly; if it does not exist, wait for a period of time Jump to the appstore
You need to determine the browser under the ios or android platform, you need to determine the WeChat browser

XML/HTML CodeCopy content to clipboard
  1. <code class="hljs" javascript="">var openApp = function () {
  2. var btnOpenApp = document.getElementById(open-app);
  3. btnOpenApp.onclick = function () {
  4. //Open local application function
  5. var open=function(url){
  6. var timeout;
  7. function try_to_open_app() {
  8. timeout = setTimeout(function(){
  9. window.location.href=url
  10. console.log()
  11. }, );
  12. }
  13. try_to_open_app();
  14. }
  15. if (/android/i.test(navigator.userAgent)) {
  16. //alert(This is Android'browser.);//This is the browser for Android platform
  17. if (/MicroMessenger/i.test(navigator.userAgent)) {
  18. alert(This is MicroMessenger browser, please use local browser to open);//This is the browser under WeChat platform
  19. }
  20. else {
  21. open(andorid application market url);
  22. }
  23. }
  24. if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {  
  25. //alert(This is iOS'browser.);//This is the browser for iOS platform
  26. if (/MicroMessenger/i.test(navigator.userAgent)) {
  27. alert (WeChat’s built-in browser does not support opening local applications, please click on the upper right corner to open it with a local browser); //This is the browser under the WeChat platform
  28. }
  29. else {
  30. open(ios application market url);
  31. }
  32. }
  33. };
  34. }code> 

 Android配置

XML/HTML Code复制内容到剪贴板
  1. <activity android:name=".ui.UploadActivity" android:screenorientation="portrait">    
  2. <intent-filter>    
  3. <data android:scheme="http" android:host="192.168.167.33" android:port="8088" android:path="/mi-tracker-web/download.html">    
  4. <action android:name="android.intent.action.VIEW">    
  5. <category android:name="android.intent.category.DEFAULT">    
  6. <category android:name="android.intent.category.BROWSABLE">    
  7. category>category>action>data>intent-filter>    
  8. activity>   

Open Application

XML/HTML Code复制内容到剪贴板
  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"    
  2. pageEncoding="ISO-8859-1"%>    
  3. <script type="text/javascript"> window.location="market://search?q=com.singtel.travelbuddy.android";script>    
  4. String str = "market://details?id="   getPackageName();    
  5. Intent localIntent = new Intent("android.intent.action.VIEW");    
  6. localIntent.setData(Uri.parse(str));    
  7. startActivity(localIntent);   

HTML配置示例
Open app
Open Market
Open Market Details
Android获取参数:

XML/HTML Code复制内容到剪贴板
  1. Uri uri = getIntent().getData(); String test1uri.getQueryParameter("arg0"); String test2uri.getQueryParameter("arg1");    
  2. webView.setWebViewClient(new WebViewClient(){    
  3. @Override    
  4. public boolean shouldOverrideUrlLoading(WebView view, String url) {    
  5. Uri uri=Uri.parse(url);    
  6. if(uri.getScheme().equals("m")&&uri.getHost().equals("my.com")){    
  7. String arg=uri.getQueryParameter("arg");    
  8. String arg=uri.getQueryParameter("arg");    
  9. }else{    
  10. view.loadUrl(url);    
  11. }    
  12. return true;    
  13. }    
  14. });  

以上所述是小编给大家介绍的Android本地应用打开方法——通过html5写连接 ,希望对大家有所帮助!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template