Android Local Application Opening Method-write connection through html5, androidhtml5

Source: Internet
Author: User

Android Local Application Opening Method-write connection through html5, androidhtml5

1. Set links in html

The Code is as follows:
Href = "[scheme]: // [host]/[path]? [Query]"

Scheme can be set to any one in the app, and the android and ios settings are the same.
2. If the local application exists, open the app directly. If the application does not exist, jump to the appstore for a period of time.
Determine whether the browser is ios or android.

Copy XML/HTML Code to clipboard
  1. <Code class = "hljs" javascript = ""> var openApp = function (){
  2. Var btnOpenApp = document. getElementById (open-app );
  3. BtnOpenApp. onclick = function (){
  4. // Open the 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 the Android 'browser.); // This is the browser on the Android platform.
  17. If (/MicroMessenger/I. test (navigator. userAgent )){
  18. Alert (This is MicroMessenger browser, open it in a local browser); // This is a platform browser.
  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 under iOS.
  26. If (/MicroMessenger/I. test (navigator. userAgent )){
  27. Alert (the built-in browser does not support opening local applications. Please click in the upper right corner to open the local browser); // This is the browser under the platform.
  28. }
  29. Else {
  30. Open (ios app market url );
  31. }
  32. }
  33. };
  34. } </Code>

Android Configuration

Copy XML/HTML Code to clipboard
  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> </action> </data> </intent-filter>
  8. </Activity>

Open Application

Copy XML/HTML Code to clipboard
  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 configuration example
Open app
Open Market
Open Market Details
Android get parameters:

Copy XML/HTML Code to clipboard
  1. Uri uri = getIntent (). getData (); String test1 = uri. getQueryParameter ("arg0"); String test2 = uri. 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. });

The above section describes how to open a local Android app-write a connection through html5. I hope this will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.