Open Android app from URL using intent-filter not working

前端 未结 3 1788
遇见更好的自我
遇见更好的自我 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);
    
    0 讨论(0)
  • 2020-11-28 09:24

    use these three in your <intent filter>

    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    
    0 讨论(0)
  • 2020-11-28 09:24

    I thought I will post this here since I spent some time looking into why my intent filter did not work. It turns out that it was working all along but matches are exact. Thus if you register your intent for http://myexample.com and you click in http://myexample.com/blah it will not work.

    Adding the following fixed the issue:

    <data android:pathPattern="/.*" />
    

    So the intent filter looks like:

    <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:host="example.com" />
                <data android:scheme="https" />
                <data android:pathPattern="/.*" />
    </intent-filter>
    
    0 讨论(0)
提交回复
热议问题