Android learning notes - wake up your APP through the webpage and pass the reference


I believe that we will find that many web pages have such functions in our life. One second ago, we were still on the web page, and one second later, we inexplicably entered their APP. So how does this effect work?
After careful study, I found that android:scheme attribute is used to complete the function. Here's my personal opinion. I think android:scheme attribute is very similar to the implicit match of Intent, or it's an implicit match. Let's get down to the point and see how to use it

Practice part

First, we create a new project and add the android:scheme attribute to Android manifest.xml

            <!--Add the following attributes, where crack It's a wake-up call action-->
                <action android:name="android.intent.action.VIEW"/>
                    <category    android:name="android.intent.category.DEFAULT"/>
                    <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="crack"/>

Now let's get the parameters of webpage turning in MainActivity

public class MainActivity extends AppCompatActivity {
    private TextView textView;
    protected void onCreate(Bundle savedInstanceState) {
        textView = findViewById(;
        Intent intent = new Intent();
        //Get parameter details
        Uri uri = intent.getData();
        if(uri != null){
            String host = uri.getHost();
            String dataString = intent.getDataString();
            String id = uri.getQueryParameter("d");
            String path = uri.getPath();
            String path1 = uri.getEncodedPath();
            String queryString = uri.getQuery();

Now we have finished the video that APP should do. Now let's start the web page
Create a new ht.html

        <meta http-equiv=content-type content="text/html;charset=utf-8">
         <title>Webpage wake up APP</title>
        <input id="txt"/>
        <input type="button" value="Submission" onclick="sub()">
            //Get content
            function sub(){
                var content = document.getElementById("txt");
                //Note here that crack is replaced by the name set in your APP
                var str = 'crack://'+content.value+'?p=91&d=15';
            //Wake up APP
             function openUrl(url){

Let's run it to see the effect

Keywords: Android Attribute xml

Added by designguy79 on Fri, 01 May 2020 02:44:39 +0300