Share button, h5 share to Android page

Keywords: Android iOS Javascript Mobile

qq. the page shared by WeChat. How to call up an app and call it to a specific page

Original: 17:34:00, April 14, 2017
  • 3808
The URL Scheme is supported by iOS and Android platform. Only the scheme needs to be registered when the native APP is developed. When the user clicks the link, the APP will wake up automatically. With the help of the URL Router mechanism, the user can also jump to the specified page.

Steps:

(1) h5 page jump page format is written like this. For example, the jump page format is app://abc. If you need to transfer parameters, add (?) after it? Key = value)

  1. <a class="btn_hy" id="openApp">I want to share</a>  
  2.   
  3. <script type="text/javascript">  
  4.     document.getElementById('openApp').onclick = function(){  
  5.         window.location.href = "app://abc";  
  6.         window.setTimeout(function(){  
  7.                 window.location.href = "  
  8. http://xxx/mobile/xxxx.apk "; / / open the app download address provided by the app colleague
  9.         },2000)  
  10.     };  
  11. </script>  
(2) android side. It needs to be in android manifest.xml. Add an intent filter to the activity of the specified page that needs to be opened
The code is as follows:
  1. <intent-filter>  
  2.                <action android:name="android.intent.action.VIEW" />  
  3.                <category android:name="android.intent.category.DEFAULT" />  
  4.                <category android:name="android.intent.category.BROWSABLE" />  
  5.                <data  
  6.                    android:host="abc"  
  7.                    android:scheme="app" >  
  8.                </data>  
  9.    </intent-filter>  

Complete example:
  1. <activity  
  2.             android:name="com.example.app.ui.WebViewActivity"  
  3.             android:label="@string/app_name"  
  4.             android:screenOrientation="portrait"  
  5.             android:windowSoftInputMode="stateHidden|adjustPan" >  
  6.             <intent-filter>  
  7.                 <action android:name="android.intent.action.VIEW" />  
  8.                 <category android:name="android.intent.category.DEFAULT" />  
  9.                 <category android:name="android.intent.category.BROWSABLE" />  
  10.                 <data  
  11.                     android:host="abc"  
  12.                     android:scheme="app" >  
  13.                 </data>  
  14.             </intent-filter>  
  15.         </activity>  
app://abc
Here, sheme is the jump address written in h5 above, corresponding to app
The host here is the jump address written in h5 above, corresponding to abc
Be careful not to write wrong here.
Reprinted from: https://blog.csdn.net/bangyingqing/article/details/70174519

Posted by diesel on Fri, 03 Apr 2020 07:55:32 -0700