简体   繁体   中英

Android app link is not working fine

I've been playing with app links with a test example but it's not working in my case.

I've created two html files source.html and some_html_file.html within the assets directory.I'm loading source.html file within a webview and that has button and I'm navigating to some_html_file.html using that button. See the source you'll get to know what I'm doing here.

source.html

<html>
   <form name = "type_1" action="some_html_file.html">
        <input type="submit" value="Example 1 - open some html file"/>
   </form>
   <form name = "type_2" action="example2://node/news/23">
       <input type="submit" value="Example 2 - go to news 23"/>
   </form>
</html>

some_html_file.html

<html>
<head>
    <meta property="al:android:url" content="example://node/news/23" />
    <meta property="al:android:package" content="com.example.uritest" />
    <meta property="al:android:app_name" content="UriTest" />
</head>
    <h3>This is uri test page.</h3>
</html>

Problem

So clicking the first button, I'm expecting that android os should read the <meta> tags of the target html file and will show my activity which has the logic to handle the intent.

AndroidManifest.xml

       <activity android:name=".HandleUriActivity">

            <intent-filter>
                <data
                    android:scheme="example"
                    />

                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <data
                    android:scheme="example2"
                    />

                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

Any help would be appreciated.

From the logcat I can see that -

D/WebViewCallback: shouldOverrideUrlLoading=file:///android_asset/some_html_file.html? W/WebViewCallback: No application can handle file:///android_asset/some_html_file.html?

Update :

I've updated my question. I've just added one more form with action. Check form type_2 in source.html . Button is Example 2 - go to news 23 is working fine and I'm getting the following data on HandleUriActivity activity.

host = node
authority = node
path = /news/23

My question is how do I work with the first case ie android os should open my activity while opening a page(some_html_file.html) that has meta-data tags.

Update #2 :

I do agree with you @Eric B . But It is not working if I've a different app.

I've a webpage with the following meta data on my test website.

<head>
    <meta property="al:android:url" content="example://node/news/23" />
    <meta property="al:android:package" content="com.example.uritest" />
    <meta property="al:android:app_name" content="UriTest" />
</head>

When I'm opening this page within Google Chrome, Chrome didn't show my app. It directly opens the webpage.

Deep Linking is implemented with the motive in mind that your app should be opened when a link is clicked in another browser. In your case your browser (WebView) exists within your app, which doesn't make sense of using Deep Linking, you could simply open up your particular activity using this code:

webView.setWebViewClient(new WebViewClient() { 
            public boolean shouldOverrideUrlLoading(WebView view, String url){
                if(url.equals(YOUR_URL))
                {
                   // Open Activity here
                }
                webView.loadUrl(url); 
                return false; 
            } 
        });

You can see my answer here regarding Deep Linking.

UPDATE

Change your manifest like this:

   <activity android:name=".HandleUriActivity">

        <intent-filter>
                    <data android:scheme="http"
          android:host="rahulchaurasia3592.github.io" >

            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM