Android 原生工程配置

AndroidManifest.xml入口的Activity中加入以下intent-filter

  1. <!-- 应用入口 -->
  2. <activity
  3. android:name="io.dcloud.PandoraEntry"
  4. android:theme="@style/TranslucentTheme"
  5. android:screenOrientation="portrait"
  6. android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale"
  7. android:hardwareAccelerated="true"
  8. android:windowSoftInputMode="adjustResize">
  9. ......
  10. <intent-filter>
  11. <action android:name="android.intent.action.VIEW"/>
  12. <category android:name="android.intent.category.DEFAULT"/>
  13. <category android:name="android.intent.category.BROWSABLE"/>
  14. <data android:scheme="test" android:host="abc.com" android:path="/entry"/>
  15. </intent-filter>
  16. </activity>

其中,scheme就相当于协议,host就相当于域名,path就相当于路径,以上配置完整的URI为:

  1. test://abc.com/entry

在网页中跳转到APP

直接上代码:

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="apple-mobile-web-app-capable" content="yes">
  6. <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
  7. <title>唤醒APP</title>
  8. <meta id="viewport" name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,minimal-ui">
  9. </head>
  10. <body>
  11. <div>
  12. <a id="J-call-app" href="javascript:;" class="label">立即打开&gt;&gt;</a>
  13. <input id="J-download-app" type="hidden" name="storeurl" value="https://file.lizhiboxue.com/shianonline/apk/sa-learn.apk">
  14. </div>
  15. <script>
  16. (function(){
  17. /*获取UA标识,并转为小写*/
  18. let ua = navigator.userAgent.toLowerCase();
  19. let config = {
  20. /*scheme:必须*/
  21. scheme_IOS: 'test://abc.com/entry',
  22. scheme_Adr: 'test://abc.com/entry',
  23. download_url: document.getElementById('J-download-app').value,
  24. timeout: 600
  25. };
  26. function openclient() {
  27. let startTime = Date.now();
  28. let ifr = document.createElement('iframe');
  29. /*通过UA标识,判断是否是苹果系统*/
  30. ifr.src = ua.indexOf('os') > 0 ? config.scheme_IOS : config.scheme_Adr;
  31. ifr.style.display = 'none';
  32. document.body.appendChild(ifr);
  33. let t = setTimeout(function() {
  34. let endTime = Date.now();
  35. if (!startTime || endTime - startTime < config.timeout + 200) {
  36. window.location = config.download_url;
  37. }
  38. }, config.timeout);
  39. window.onblur = function() {
  40. clearTimeout(t);
  41. }
  42. }
  43. window.addEventListener("DOMContentLoaded", function(){
  44. document.getElementById("J-call-app").addEventListener('click',openclient,false);
  45. }, false);
  46. })()
  47. </script>
  48. </body>
  49. </html>

以上,先判断平台类型(iOS、Android),如果应用存在,打开应用,若不存在,通过URL下载应用。

跳转到APP并传参

TODO…

跳转到指定的uniapp页面

TODO…

参考资料