0

I've been learning Java for some time now to develop Android-apps. At this point, I want my website to redirect to my app. This should be possible using an Intent-filter for my website-url. I have used the stackoverflow.com homepage as example.

I use this code in a MainActivity section in the Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="nl.example.webitent" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <data android:scheme="http" android:host="stackoverflow.com"/>
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <action android:name="android.intent.action.VIEW" />
            </intent-filter>
        </activity>
    </application>

</manifest>

So far, nothing interesting. This is literally a blank activity in a new project with the intent-filter added. I have target-sdk 21 and minimal sdk 16. However, whatever I try, it doesn't fire when I go to stackoverflow.com, neither directly nor through a href.

What is going on, or what am I doing wrong?

Ivotje50
  • 518
  • 7
  • 15

1 Answers1

0

When you visit stackoverflow.com in your browser, the intent is not fired. An intent is fired only if the app explicitly does that. This is the case if the app (your browser) is not supposed to open your url scheme. For example mailto is opened in your Mail-App. So you have to create your own URL-scheme like this

        <intent-filter>
            <data android:scheme="myweb" android:host="stackoverflow.com"/>
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <action android:name="android.intent.action.VIEW" />
        </intent-filter>

Then a link to myweb://stackoverflow.com would open your app.

Christian
  • 4,596
  • 1
  • 26
  • 33
  • Problem is that when someone without my app turns to myweb://stackoverflow.com it comes up with a nasty error. I know twitter does this, you can visit the mobile website but if you have the app installed, it will ask you to open in the app. – Ivotje50 Aug 03 '15 at 21:28
  • this is a missing feature, the only thing I fount is to check the time the page is visible after clicking the link with javascript, see for example http://stackoverflow.com/questions/627916/check-if-url-scheme-is-supported-in-javascript – Christian Aug 03 '15 at 23:38