4

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 i.e. 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.

Community
  • 1
  • 1
Rahul Chaurasia
  • 1,601
  • 2
  • 18
  • 37

1 Answers1

1

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>
Community
  • 1
  • 1
Eric B.
  • 4,622
  • 2
  • 18
  • 33
  • Thanks @Eric B. Please check my updated question. Please help me if you know what I'm doing wrong. – Rahul Chaurasia Dec 16 '15 at 09:58
  • @RahulChaurasia According to your edit, and the documentation [here](http://developer.android.com/training/app-indexing/deep-linking.html). You HandleUriActivity will only be opened by Chrome if and only if you are accessing a url that starts with either `example://some_url` or `example2://some_url` – Eric B. Dec 16 '15 at 10:10
  • my page url starts with http://my_domain/news/some_news_item.html with the meta data that I had written – Rahul Chaurasia Dec 16 '15 at 10:22
  • I dont understand can you please, show the exact url on which you want your app to be opened up. – Eric B. Dec 16 '15 at 10:25
  • So what you want is that when some opens the above link in chrome they should be redirected to your app, right? – Eric B. Dec 16 '15 at 10:36
  • I have edited my answer, please see it, and i highly recommend you read the documentation i linked above. – Eric B. Dec 16 '15 at 10:48
  • Thanks, I had already done that and it was working fine for me. But I want to use custom scheme (example) because I want to get the following data "node/news/23" – Rahul Chaurasia Dec 16 '15 at 11:00
  • Does this mean the whole path will be "rahulchaurasia3592.github.io/node/news/23", right? – Eric B. Dec 16 '15 at 11:01
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/98095/discussion-between-rahul-chaurasia-and-eric-b). – Rahul Chaurasia Dec 16 '15 at 11:02
  • Hey Rahul, I hope you worked out how to deep link with app links. If you want to try a very simple approach with far more capability than regular deep linking / app links, check out branch.io – Evan Jan 22 '16 at 23:01