【问题标题】:Redirect Uri not opening the Android App directly in OAuth2 - Deep link is already configured重定向 Uri 未直接在 OAuth2 中打开 Android 应用程序 - 已配置深层链接
【发布时间】:2020-02-04 08:07:45
【问题描述】:

要求:打开一个 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>

在浏览器中打开第一个 api 调用的代码:

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);
            }
        });

在这里处理 Intent 部分

  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 调用链接在浏览器中打开并且我批准它的登录请求时,它会在浏览器本身中显示重定向 URI并且控件不会直接返回到我的应用程序。相反,它会冻结,然后我需要单击“在 chrome 中打开”(附加),然后它会提示我是否要打开应用程序并选择控件返回到我的应用程序。任何指针将不胜感激。提前致谢! 编辑:代码在第一次执行期间正常工作,但第二次出现此问题。

【问题讨论】:

    标签: android deep-linking


    【解决方案1】:

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

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

    现在,它工作正常。

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

    【讨论】:

    • 我也面临同样的问题。重定向 URI 正在打开应用程序,而应用程序的打开支持的链接设置设置为“在此应用程序中打开”,但是当其“每次询问”重定向 URI 未打开应用程序时。它只是在自定义 chrome 选项卡上显示 404 页面。
    猜你喜欢
    • 2016-06-26
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    • 2018-02-12
    • 2020-06-05
    • 1970-01-01
    • 2022-01-08
    • 2021-07-21
    相关资源
    最近更新 更多