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">
开发者_Go百科<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!
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.
I'm not sure, I can test later, but I think when you enter it in the browser, you're telling the browser to open it.
What might be needed is to actually click a link that loads that scheme://host combination, not only type it into the "url bar".
Edit: Sorry, I did a quick test, and this is not the case. Still, the trouble might be that the browser tries to resolve the host before it actually gets to the intent part and offers you to open it with your app. Does it work with a real url (assuming that I was right in guessing that was not a real resolving url?)
The intent-filter worked fine for http and https schemes as long as I used a real domain. However, the popup asking the user whether they want to use the browser instead of the app was unacceptable. I tried using my own scheme but that didn't work (no idea why).
For the purposes of my app it was sufficient to create an activity with a WebView instead of using the fully-fleged browser and I overrode the shouldOverrideUrlLoading of the WebViewClient and trap requests for my uri and send them directly to my activity. This solution actually works better than what I was trying to do before because the user doesn't get a prompt, and I don't have to define a global scheme.
Ben...
Check with changing the Scheme to https instead of http.
精彩评论