问题描述
我有一个可以从配置的 Android
启动的 App Link
应用程序。
通过点击浏览器或其他电子邮件客户端(如 Gmail
等)中的链接,我的应用程序作为单独的应用程序正确启动。
但是对于 Outlook
,当我点击电子邮件中的链接时,我的应用程序会在 Outlook 应用程序中启动。查看屏幕截图。
另一方面,如果我只需点击 Outlook 中的 YouTube
视频链接,YouTube 应用就会作为单独的应用启动。
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<provider
android:name=".GenericFileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<Meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<activity
android:name=".MainActivity"
android:theme="@style/AppThemeNoActionBar"
android:resizeableActivity="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:host="xx.xxxxx.com" android:scheme="https" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.broWSABLE" />
</intent-filter>
</activity>
<activity
android:name=".WebActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/AppThemeNoActionBar" />
<activity
android:name="com.zos.sigcapesign.SplashActivity"
android:theme="@style/AppThemeNoActionBar" />
</application>
经过一番搜索后,我尝试更改清单中的启动模式值,如下所示:android:launchMode="singleTask"
这解决了在 Outlook 中启动我的应用程序的问题,并且我的应用程序开始作为单独的应用程序启动。但它带来了新的问题。
将启动模式设置为 singleTask
后,我的应用仅第一次启动。现在,如果我的应用程序已经启动并且我再次单击该链接,则该应用程序以空白屏幕启动。在调试器中,甚至没有命中 MainActivity
。因此应用中没有任何反应,我必须将启动模式恢复为 standard
。
所以,对我来说,问题仍然是为什么我的 Android 应用程序在 Outlook 应用程序中打开?
解决方法
我能够找出问题并解决它。
我已将启动模式用作 signleTask
我遗漏的一点是,当应用程序使用 App Link
重新启动时,会调用 onNewIntent()
函数而不是 onCreate()
。所以我必须在 onNewIntent()
函数中处理 App Link 案例。
现在一切都很好。我可以将我的应用作为独立于 Outlook
、Browser
、Gmail
客户端等的应用启动。