Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my Activity not being launched by URL?

I realize there are several similar questions, but none of the accepted answers are working for me. As part of an oauth process I want a browser redirect to launch my activity. As I've seen everywhere, I have set up an intent-filter that supposedly does that:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.codesta.test"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".BrowsableActivity"
                  android:label="@string/app_name">
            <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="http" android:host="oauth.android.mydomain.com" />
            </intent-filter>
        </activity>

    </application>
</manifest>

However when I open the browser and enter http://oauth.android.mydomain.com I get the "web page not available" error page. I also tried defining my own scheme (which I've read is not generally recommended) but that didn't work either.

I am targeting api level 7 and have tested the code on emulated devices running 2.1 and 2.2 without success. Any help would be greatly appreciated!

like image 485
Ben Avatar asked Nov 05 '22 01:11

Ben


1 Answers

I encountered the same issue - As far as I can tall, several OAuth sites use a <META .../> tag to do the final redirect that you are trying to trap.

Redirects using the META tag are not caught by the Intent filter, so your code never executes. Strangely, if the same link is clicked by the user, or is redirected using a Location: header, it does trigger. There is already an open android 2.2.1 bug ticket on this, but I've lost the reference to it.

The usual workaround is to set up a real page on the callback URL, and redirect it from there using a Location: header to somewhere else that you CAN capture.

EDIT: I since tried this with a Location: header, and is seems that redirects in general to http:// are not captured, but redirecting to a different scheme (x-oauth://) is frowned upon, but works.

like image 164
Steve Davies Avatar answered Nov 15 '22 13:11

Steve Davies