Open Android app from URL using intent-filter not working

前端 未结 3 1800
遇见更好的自我
遇见更好的自我 2020-11-28 08:27

I have an Android app that people use as a replacement for a website. Hence, when users encounter an URL to the website, I want to give them the option to \"open the URL\" i

3条回答
  •  独厮守ぢ
    2020-11-28 09:13

    @nurieta, your answer did the trick for me thanks!

    One word of advice since I am dealing with potential query strings, I handled it through a bit of code in the .java in order to determine if to just open the app or to send you to a specific location in the app. My app is just a WebView that runs a JQuery mobile app.

        if(getIntent().getData()!=null){//check if intent is not null
            Uri data = getIntent().getData();//set a variable for the Intent
            String scheme = data.getScheme();//get the scheme (http,https)
            String fullPath = data.getEncodedSchemeSpecificPart();//get the full path -scheme - fragments
    
            combine = scheme+"://"+fullPath; //combine to get a full URI
        }
    
        String url = null;//declare variable to hold final URL
        if(combine!=null){//if combine variable is not empty then navigate to that full path
            url = combine;
        }
        else{//else open main page
            url = "http://www.example.com";
        }
        webView.load(url);
    

提交回复
热议问题