11

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?

Joelio
  • 4,621
  • 6
  • 44
  • 80
  • `android:pathPrefix` attribute specifies a partial path that is matched against only the initial part of the path in the Intent object. – Shark Nov 25 '19 at 17:11
  • Hi @Shark, yes, this is the first part of my path. To make this easier, I put up a web page at http://www.joelnylund.com/ to show, the first link uses "myapp" and the 2nd link uses http. The first works fine, but I cannot get the 2nd one to work. – Joelio Dec 02 '19 at 19:08

1 Answers1

0

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.

Sina
  • 2,683
  • 1
  • 13
  • 25
  • 1
    I tried this exact setup (with my domain) and no luck, the intent filter is not fired. I cut and pasted this into my AndroidManifest.xml. I just changed example.com to my domain name. Any ideas what could be wrong? – Joelio Dec 02 '19 at 19:05
  • I just updated my answer. I don't see any problem in your code, just tried to mention some points from another answer by one of android devs. – Sina Dec 03 '19 at 09:40