重定向 Uri 未在 OAuth2 中直接打开 Android 应用程序 - 深度 link 已配置

Redirect Uri not opening the Android App directly in OAuth2 - Deep link is already configured

要求:打开 URL 并将响应返回给应用程序并将用户重定向回我的应用程序,因为随后还有其他 API 调用。

<intent-filter
            android:autoVerify="true"
            android:order="1">
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="ab.bc.cd"
               android:port="11001"/>
               <data android:scheme="https" />
                <data android:scheme="http" />
               <data android:pathPrefix="/abc.html" />
        </intent-filter>
    </activity>

Code to open the first api call in the browser:

if (!TextUtils.isEmpty(url)) {
        final CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
        CustomTabActivityHelper.openCustomTab(MainActivity.this, customTabsIntent, Uri.parse(url), new WebviewFallback() {
            @Override
            public void openUri(Activity activity, Uri uri) {
                    setupCustomTabs(uri);
            }
        });

Handling the Intent part here

  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    final String schemeName = intent.getScheme();
    final Uri data = intent.getData();
    if (data != null && data.getHost() != null && data.getHost().equalsIgnoreCase("")) {
        return;
    }
    if (!TextUtils.isEmpty(schemeName) && schemeName.equalsIgnoreCase(UAEPassConstant.SCHEME)) {
        final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
        if (fragment != null && !(fragment instanceof DisplayFragment)) {
            setFragment(new DisplayFragment(), null, false);
        }
        final String encodedQuery = intent.getData().getEncodedQuery();
        if (!TextUtils.isEmpty(encodedQuery) && !encodedQuery.contains(UAEPassConstant.ERROR_DESCRIPTION)) {
            final String[] queryDataArray = encodedQuery.split("=|&"); // this is to fetch a code value which comes as a result of the first api call
            final LoginApiCall uaePassCall = new LoginApiCall(MainActivity.this, queryDataArray[1], new IUAEPassCallBack() {
                @Override
                public void onSuccessLogin(String userInfoJson, String tokenJson) {
                    Log.e("userInfo", userInfoJson);
                    Log.e("tokenJson", tokenJson);
                    final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
                    if (fragment instanceof DisplayFragment) {
                        ((DisplayFragment) fragment).LoggingData(userInfoJson);

                    }
                }

会发生什么:当我运行这段代码一切正常但是当第一个API调用link在浏览器中打开时我批准了它的登录请求,它在浏览器本身中显示了重定向 URI,并且控件不会直接返回到我的应用程序。相反,它冻结了,然后我需要单击 "Open in chrome"(已附),然后它会提示我是否要打开该应用程序并选择控件返回我的应用程序。任何指针将不胜感激。提前致谢! 编辑:代码在第一次执行期间正常工作,但第二次我遇到了这个问题。

我做了很多事情,但最后当我将代码更改为打开自定义标签时:

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();

            CustomTabsIntent customTabsIntent = builder.build();
            customTabsIntent.launchUrl(this, Uri.parse(url));

现在,它工作正常。

注意:仅此一项是行不通的。我检查了几乎所有与此问题相关的 link,但事实证明,我使用的深度 link 是错误的。请确保您正确设置方案和主机。我花了 4 天时间才搞清楚这个问题。