【发布时间】:2021-04-16 00:26:35
【问题描述】:
我正在尝试在一个非常基本的 Android 应用程序中使用隐式深层链接。目标是使用 Strava 的 OAuth 服务器演示基本的 OAuth 流程,以访问他们的 API。
Strava 自动将“localhost”以及您在注册“应用”时输入的任何授权回调域列入白名单。我依赖本地主机。
我有一个活动加上一些片段。在 Android Studio 中,我添加了一个指向非初始片段的深层链接。我的初始片段要求输入登录名和密码,然后创建一个 IntentUri 来访问 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。
即使 Strava 因任何原因无法工作,我至少应该能够让快捷方式工作。
感谢任何帮助。
-------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>
----------shortcuts.xml---------- ---------------
<?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>
--------------nav_graph.xml------ -------------------
<?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>
【问题讨论】:
标签: java android oauth-2.0 deep-linking