我要在应用程序中打开“深度链接”对话框,因此在清单中定义了以下内容:
<activity
android:name=".ActivityA"
android:screenOrientation="portrait"
android:theme="@style/AppBaseTheme"
android:windowSoftInputMode="stateHidden|stateVisible" >
<intent-filter>
<data android:scheme="rentaldashboard" />
<data android:scheme="https" />
<data android:scheme="http" />
<data android:host="my.site.com" />
<data android:pathPattern=".*" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
<activity
android:name=".ActitivtyB"
android:screenOrientation="portrait"
android:theme="@style/AppBaseTheme"
android:windowSoftInputMode="stateHidden|stateVisible" >
<intent-filter>
<data android:scheme="rentalreset" />
<data android:scheme="https" />
<data android:scheme="http" />
<data android:host="my.site.com" />
<data android:pathPattern=".*" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
activitya和activityb使用架构,当我运行上面的代码时,它显示如下对话框:
对话框中列出了我的应用程序徽标两次。我希望每次只为两个活动分别打开一个徽标。你知道我怎样才能做到吗?
最佳答案
如果您只有部分url,比如activitya的/user
或/news
,/admin
只是activityb的,那么您应该改进路径过滤器。顺便说一下,它们必须以斜线开头,而且模式不是正则表达式。
如果要支持自定义方案和http(s)url,则应使用多个意图筛选器:
<activity
android:name=".ActivityA"
android:screenOrientation="portrait"
android:theme="@style/AppBaseTheme"
android:windowSoftInputMode="stateHidden|stateVisible" >
<intent-filter>
<data android:scheme="https" />
<data android:scheme="http" />
<data android:host="dev.worldofrental.com" />
<data android:host="www.worldofrental.com" />
<data android:pathPrefix="/urlredirect/getstarted" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
<intent-filter>
<data android:scheme="your.package.name"
android:host="getstarted" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
<activity
android:name=".ActitivtyB"
android:screenOrientation="portrait"
android:theme="@style/AppBaseTheme"
android:windowSoftInputMode="stateHidden|stateVisible" >
<intent-filter>
<data android:scheme="https" />
<data android:scheme="http" />
<data android:host="dev.worldofrental.com" />
<data android:host="www.worldofrental.com" />
<data android:pathPrefix="/urlredirect/resetpassword" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
<intent-filter>
<data android:scheme="your.package.name"
android:host="resetpassword" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
一般来说,我建议使用包名作为方案,以确保没有其他应用程序会“窃取”您的意图。