Java OAuth回调URI的Android深度链接不工作

Java OAuth回调URI的Android深度链接不工作,java,android,oauth-2.0,deep-linking,Java,Android,Oauth 2.0,Deep Linking,我试图在一个非常基本的Android应用程序中获得一个隐含的深层链接。我们的目标是用Strava的OAuth服务器演示一个基本的OAuth流,以访问它们的API Strava会自动将“localhost”以及注册“app”时输入的任何授权回调域列入白名单。我依赖本地主机 我有一个活动加上一些片段。在Android Studio中,我添加了一个深度链接,指向一个并非初始片段的片段。我的初始片段要求输入登录名和密码,然后创建一个意图来访问Strava OAuth服务器。这很好,它将在OAuth请求中

我试图在一个非常基本的Android应用程序中获得一个隐含的深层链接。我们的目标是用Strava的OAuth服务器演示一个基本的OAuth流,以访问它们的API

Strava会自动将“localhost”以及注册“app”时输入的任何授权回调域列入白名单。我依赖本地主机

我有一个活动加上一些片段。在Android Studio中,我添加了一个深度链接,指向一个并非初始片段的片段。我的初始片段要求输入登录名和密码,然后创建一个意图来访问Strava OAuth服务器。这很好,它将在OAuth请求中传递回调URI以及授权请求。问题是回调URI没有到达深层链接

我尝试了回调URI的几种组合:

  • http://localhost/fibonacci/itemFragment
  • localhost/fibonacci/itemFragment
  • myapp://localhost/fibonacci/itemFragment
  • 这些都不起作用(是的,我总是在OAuth请求和描述深度链接的xml中同时更新URI

  • 回调URI触发打开浏览器的请求
  • Strava站点将回调uri标记为无效
  • 回调似乎没有发生
  • 我也尝试通过创建快捷方式来测试这一点,但每次浏览器都会尝试打开快捷方式。
    下面是我的android清单文件、shortcuts.xml文件和nav_graph.xml文件

    我至少应该能够找到工作的捷径,即使斯特拉瓦出于任何原因不工作

    感谢您的帮助

    -------------------AndroidManifest.xml---------------------------------

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.fibonacci">
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/Theme.Fibonacci">
            <activity
                android:name=".MainActivity"
                android:label="@string/app_name"
                android:theme="@style/Theme.Fibonacci.NoActionBar">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
                <meta-data android:name="android.app.shortcuts"
                    android:resource="@xml/shortcuts" />
            </activity>
        </application>
    
    </manifest>
    
    <?xml version="1.0" encoding="utf-8"?>
    <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
        <shortcut
            android:shortcutId="RichShortcut"
            android:enabled="true"
            android:shortcutShortLabel="@string/static_shortcut_label_short"
            android:shortcutLongLabel="@string/static_shortcut_label_long"
            android:shortcutDisabledMessage=
                "@string/static_shortcut_disabled_message">
            <!--        android:icon="@drawable/donut_with_sprinkles">-->
            <intent
                android:action="android.intent.action.VIEW"
                android:data="myapp://localhost/fibonacci/itemFragment" />
        </shortcut>
    </shortcuts>
    
    <?xml version="1.0" encoding="utf-8"?>
    <navigation xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/nav_graph"
        app:startDestination="@id/loginFragment">
    
        <fragment
            android:id="@+id/FirstFragment"
            android:name="com.example.fibonacci.FirstFragment"
            android:label="@string/first_fragment_label"
            tools:layout="@layout/fragment_first">
    
            <action
                android:id="@+id/action_FirstFragment_to_SecondFragment"
                app:destination="@id/SecondFragment" />
        </fragment>
        <fragment
            android:id="@+id/SecondFragment"
            android:name="com.example.fibonacci.SecondFragment"
            android:label="@string/second_fragment_label"
            tools:layout="@layout/fragment_second">
    
            <action
                android:id="@+id/action_SecondFragment_to_FirstFragment"
                app:destination="@id/FirstFragment" />
        </fragment>
        <fragment
            android:id="@+id/loginFragment"
            android:name="com.example.fibonacci.ui.login.LoginFragment"
            android:label="fragment_login"
            tools:layout="@layout/fragment_login" />
        <fragment
            android:id="@+id/itemFragment"
            android:name="com.example.fibonacci.ItemFragment"
            android:label="fragment_item_list"
            tools:layout="@layout/fragment_item_list">
            <deepLink
                android:id="@+id/deepLink"
                app:uri="myapp://localhost/fibonacci/itemFragment" />
        </fragment>
    </navigation>
    
    
    
    ----------------------shortcuts.xml-------------------------------------

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.fibonacci">
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/Theme.Fibonacci">
            <activity
                android:name=".MainActivity"
                android:label="@string/app_name"
                android:theme="@style/Theme.Fibonacci.NoActionBar">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
                <meta-data android:name="android.app.shortcuts"
                    android:resource="@xml/shortcuts" />
            </activity>
        </application>
    
    </manifest>
    
    <?xml version="1.0" encoding="utf-8"?>
    <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
        <shortcut
            android:shortcutId="RichShortcut"
            android:enabled="true"
            android:shortcutShortLabel="@string/static_shortcut_label_short"
            android:shortcutLongLabel="@string/static_shortcut_label_long"
            android:shortcutDisabledMessage=
                "@string/static_shortcut_disabled_message">
            <!--        android:icon="@drawable/donut_with_sprinkles">-->
            <intent
                android:action="android.intent.action.VIEW"
                android:data="myapp://localhost/fibonacci/itemFragment" />
        </shortcut>
    </shortcuts>
    
    <?xml version="1.0" encoding="utf-8"?>
    <navigation xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/nav_graph"
        app:startDestination="@id/loginFragment">
    
        <fragment
            android:id="@+id/FirstFragment"
            android:name="com.example.fibonacci.FirstFragment"
            android:label="@string/first_fragment_label"
            tools:layout="@layout/fragment_first">
    
            <action
                android:id="@+id/action_FirstFragment_to_SecondFragment"
                app:destination="@id/SecondFragment" />
        </fragment>
        <fragment
            android:id="@+id/SecondFragment"
            android:name="com.example.fibonacci.SecondFragment"
            android:label="@string/second_fragment_label"
            tools:layout="@layout/fragment_second">
    
            <action
                android:id="@+id/action_SecondFragment_to_FirstFragment"
                app:destination="@id/FirstFragment" />
        </fragment>
        <fragment
            android:id="@+id/loginFragment"
            android:name="com.example.fibonacci.ui.login.LoginFragment"
            android:label="fragment_login"
            tools:layout="@layout/fragment_login" />
        <fragment
            android:id="@+id/itemFragment"
            android:name="com.example.fibonacci.ItemFragment"
            android:label="fragment_item_list"
            tools:layout="@layout/fragment_item_list">
            <deepLink
                android:id="@+id/deepLink"
                app:uri="myapp://localhost/fibonacci/itemFragment" />
        </fragment>
    </navigation>
    
    
    
    --------------------------nav_graph.xml-------------------------------------

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.fibonacci">
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/Theme.Fibonacci">
            <activity
                android:name=".MainActivity"
                android:label="@string/app_name"
                android:theme="@style/Theme.Fibonacci.NoActionBar">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
                <meta-data android:name="android.app.shortcuts"
                    android:resource="@xml/shortcuts" />
            </activity>
        </application>
    
    </manifest>
    
    <?xml version="1.0" encoding="utf-8"?>
    <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
        <shortcut
            android:shortcutId="RichShortcut"
            android:enabled="true"
            android:shortcutShortLabel="@string/static_shortcut_label_short"
            android:shortcutLongLabel="@string/static_shortcut_label_long"
            android:shortcutDisabledMessage=
                "@string/static_shortcut_disabled_message">
            <!--        android:icon="@drawable/donut_with_sprinkles">-->
            <intent
                android:action="android.intent.action.VIEW"
                android:data="myapp://localhost/fibonacci/itemFragment" />
        </shortcut>
    </shortcuts>
    
    <?xml version="1.0" encoding="utf-8"?>
    <navigation xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/nav_graph"
        app:startDestination="@id/loginFragment">
    
        <fragment
            android:id="@+id/FirstFragment"
            android:name="com.example.fibonacci.FirstFragment"
            android:label="@string/first_fragment_label"
            tools:layout="@layout/fragment_first">
    
            <action
                android:id="@+id/action_FirstFragment_to_SecondFragment"
                app:destination="@id/SecondFragment" />
        </fragment>
        <fragment
            android:id="@+id/SecondFragment"
            android:name="com.example.fibonacci.SecondFragment"
            android:label="@string/second_fragment_label"
            tools:layout="@layout/fragment_second">
    
            <action
                android:id="@+id/action_SecondFragment_to_FirstFragment"
                app:destination="@id/FirstFragment" />
        </fragment>
        <fragment
            android:id="@+id/loginFragment"
            android:name="com.example.fibonacci.ui.login.LoginFragment"
            android:label="fragment_login"
            tools:layout="@layout/fragment_login" />
        <fragment
            android:id="@+id/itemFragment"
            android:name="com.example.fibonacci.ItemFragment"
            android:label="fragment_item_list"
            tools:layout="@layout/fragment_item_list">
            <deepLink
                android:id="@+id/deepLink"
                app:uri="myapp://localhost/fibonacci/itemFragment" />
        </fragment>
    </navigation>
    

    您尚未在清单中的导航图中注册您的
    ,因此它永远不会被Android操作系统触发

    根据:

    要启用隐式深度链接,还必须添加到应用程序的manifest.xml文件中。向指向现有导航图的活动添加单个
    元素,如下例所示:

    
    
    Ah.导航图显示在其他地方(抱歉,没有包括所有文件)。它在“content\u main.xml”中,描述了这样一个片段:app:navGraph=“@navigation/nav\u graph”/>我需要你的行加上我的content\u main.xml中的行吗?哈,它起作用了!两个地方都需要,是的。