Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use an intent-filter on customtabs using https scheme?

My app opens up a customtabs browser, and when the browser encounters a certain url I want to pop back open my app.

I found this posting that works - Android - create a schema for my app that will open from a webpage link using a protocol called "myapp"

I would prefer to use http/https protocol to trigger my app, but for some reason it doesn't seem to work.

Specifically this works:

       <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:scheme="myapp" />
       </intent-filter>

When the browser redirects to "myapp://10.2.2.0:3001/cats" my app opens back up, yay!

The problem is when I try this (or any of 100 other things I have tried)

            <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:scheme="https" android:host="10.0.2.2" />
                <data android:scheme="http" android:host="10.0.2.2" />
                <data android:pathPrefix="/cats" />
            </intent-filter>

When my app redirects to "http://10.2.2.0:3001/cats" It doesn't work, as a negative side effect also it asks me what I want to do when opening up customTabs (use google chrome, use a different app), no matter what I pick, the intent-filter doesn't get fired.

Is there a restriction on using http/https intent filters? What am I doing wrong?

like image 265
Joelio Avatar asked Nov 21 '19 23:11

Joelio


1 Answers

Answer from: Launch custom android application from android browser(read all answers, could be useful)

All above answers didn't work for me with CHROME as of 28 Jan 2014

my App launched properly from http://example.com/someresource/ links from apps like hangouts, gmail etc but not from within chrome browser.

to solve this, so that it launches properly from CHROME you have to set intent filter like this

    <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"
            android:pathPrefix="/someresource/"
            android:scheme="http" />
        <data
            android:host="www.example.com"
            android:pathPrefix="/someresource/"
            android:scheme="http" />
    </intent-filter>

note the pathPrefix element

your app will now appear inside activity picker whenever user requests http://example.com/someresource/ pattern from chrome browser by clicking a link from google search results or any other website

Update

You should have no problem with what I see from your code. Just try to solve your problem without using a custom scheme.

Read this answer: explaining why not to use a custom scheme

Also, in case you have several actions check if putting each action in a separate intent-filter and the order of intent-filters has any effects on your problem. Finally, have you tried to use intent scheme? That worth a try too.

like image 123
Sina Avatar answered Oct 21 '22 08:10

Sina