I'm trying to get an implicit deep link working in a very basic Android app. The goal is to demonstrate a basic OAuth flow with Strava's OAuth server to get access to their API.
Strava automatically whitelists 'localhost' plus any authorization callback domain you enter when you register your 'app'. I'm relying on localhost.
I have an activity plus some fragments. In Android Studio I've added a deep link to a fragment that isn't the initial one. My initial fragment asks for a login name and password then creates an IntentUri to hit the Strava OAuth server. This goes just fine and it passes the callback URI in the OAuth request along with the grant requests. The problem is that the callback URI does not go to the deep link.
I've tried a few combinations for callback URIs:
- http://localhost/fibonacci/itemFragment
- localhost/fibonacci/itemFragment
- myapp://localhost/fibonacci/itemFragment
None of these work (yes I always update the URI in the OAuth request and in xml that describes the deep link at the same time.
- the callback URI triggers a request to open the browser.
- the Strava site flags the callback uri as invalid.
- the callback doesn't seem to occur.
I've also tried to test this by creating a shortcut but in each the browser tries to open the shortcut.
Below are my android manifest file, my shortcuts.xml file and my nav_graph.xml.
I should at least be able to get the shortcut to work even if Strava wouldn't work for whatever reason.
Any help is appreciated.
-------------------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>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…