我正在尝试使用Android Chrome自定义标签实施OAuth2流程,但当Chrome自定义标签收到带有我的应用的位置/方案的302时,我的应用始终关闭(不会崩溃).
如果我创建一个带有ahref链接并在其上手动触摸的HTML页面,Chrome自定义选项卡正在切换到我的应用程序.
似乎在Chrome自定义选项卡中处理服务器302重定向时,它将无法正确处理我的自定义应用程序方案......但为什么呢?
如果我在股票浏览器或WebView中尝试相同的重定向URL,一切都正常.
这是我目前的设置:
MainActiviy.java
Button btnChromeCustomTab = (Button) findViewById(R.id.btnChromeCustomTab);
btnChromeCustomTab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
String packageName = CustomTabsHelper.getPackageNameToUse(MainActivity.this);
customTabsIntent.intent.setPackage(packageName);
Uri theLocationUri = Uri.parse(URL);
customTabsIntent.launchUrl(MainActivity.this, theLocationUri);
}
});
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="@string/filter_title">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myappscheme" android:host="oauth" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
这是应用程序通过HTTP 302代码接收的重定向URL:
myappscheme:// OAuth的代码= 1234567&状态= tokenCheck123
的build.gradle
android {
compileSdkVersion 23
buildToolsVersion …Run Code Online (Sandbox Code Playgroud)