【发布时间】:2021-09-01 13:59:09
【问题描述】:
我正在使用 Jetpack Navigation 进行深度链接。如果之前未打开应用程序,则深层链接不会正确重定向。但是,如果应用程序存在于内存中,则应用程序将进入前台并且深度链接正确打开。我有 2 个活动。一个 registerActivity 另一个 mainActivity。 我想在 mainActivity 的片段中使用深层链接。
这是 Jetpack Navigation 中的错误还是我在设置时忘记了什么?
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.life4.ecommerce">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:name=".ECommerceApplication"
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.ECommerce"
android:requestLegacyExternalStorage="true"
android:usesCleartextTraffic="true">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity android:name=".view.RegisterActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".view.MainActivity"
android:windowSoftInputMode="adjustResize">
<nav-graph android:value="@navigation/nav_main" />
</activity>
</application>
</manifest>
这是导航图的一部分
<fragment
android:id="@+id/productDetailsFragment"
android:name="com.life4.ecommerce.view.ProductDetailsFragment"
android:label="fragment_product_details"
tools:layout="@layout/fragment_product_details">
<argument
android:name="productID"
app:argType="integer" />
<action
android:id="@+id/action_productDetailsFragment_to_profileFragment"
app:destination="@id/profileFragment" />
<action
android:id="@+id/action_productDetailsFragment_to_imageDetailsFragment"
app:destination="@id/imageDetailsFragment" />
<deepLink
android:id="@+id/deepLink2"
app:uri="example.com/pro/{productID}" />
</fragment>
【问题讨论】:
-
"如果之前没有打开过应用,Deeplink 就不会正确重定向。" - 那么会发生什么?您的活动是否开放?
-
是的,只有开放的活动
标签: android deep-linking android-jetpack-navigation android-deep-link