Ben*_*Ben 5 android intentfilter android-emulator android-activity
我意识到有几个类似的问题,但没有一个接受的答案对我有用.作为oauth流程的一部分,我想要一个浏览器重定向来启动我的活动.正如我到处看到的那样,我已经设置了一个意图过滤器,据说可以做到:
<?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>
Run Code Online (Sandbox Code Playgroud)
但是,当我打开浏览器并输入http://oauth.android.mydomain.com时,我得到"网页不可用"错误页面.我也尝试定义我自己的方案(我读过的通常不推荐),但这也不起作用.
我的目标是api级别7,并且已经在运行2.1和2.2的模拟设备上测试了代码而没有成功.任何帮助将不胜感激!
只要我使用真实的域,意图过滤器就可以很好地用于 http 和 https 方案。但是,弹出窗口询问用户是否要使用浏览器而不是应用程序是不可接受的。我尝试使用自己的方案,但没有成功(不知道为什么)。
就我的应用程序而言,使用 WebView 创建活动就足够了,而不是使用成熟的浏览器,并且我覆盖了 WebViewClient 的 shouldOverrideUrlLoading 并捕获对我的 uri 的请求并将它们直接发送到我的活动。这个解决方案实际上比我之前尝试做的效果更好,因为用户没有得到提示,而且我不必定义全局方案。