android - Android应用程序图标快捷方式未启动活动
问题描述
我正在尝试在 Android 上实现应用程序图标快捷方式。我遵循了文档,但从快捷方式启动应用程序时遇到问题。每次我单击应用程序图标快捷方式时,都没有任何反应。这是我AndroidManifest.xml
文件中的代码:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.package.myapp">
<application
android:name=".MyApp"
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.NoActionBar"
android:usesCleartextTraffic="${usesCleartextTraffic}"
tools:ignore="ExportedService,GoogleAppIndexingWarning,UnusedAttribute">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<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"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="UnusedAttribute">
<shortcut
android:enabled="true"
android:icon="@drawable/ic_send"
android:shortcutId="send_funds"
android:shortcutLongLabel="@string/LBL_SEND_FUNDS"
android:shortcutShortLabel="@string/BTN_SEND">
<intent
android:action="android.intent.action.VIEW"
android:targetClass="com.package.myapp.MainActivity"
android:targetPackage="com.package.myapp" />
</shortcut>
</shortcuts>
解决方案
所以问题就在buildType
. 在发布版本以外的 s 上运行时buildType
,我遇到了问题,因为包名称与快android:targetPackage
捷方式的意图上指示的名称不同。所以我所做的是,我在各自的构建文件夹中创建了多个shortcuts.xml
不同的:targetPackage
app/src/debug/res/xml/shortcuts.xml
app/src/dev/res/xml/shortcuts.xml
app/src/staging/res/xml/shortcuts.xml
并android:targetPackage
分别设置:
android:targetPackage="com.package.myapp.debug"
android:targetPackage="com.package.myapp.dev"
android:targetPackage="com.package.myapp.staging"
感谢这个与我的问题几乎相似的SO question 。而对于Rakesh 的回答。
推荐阅读
- angular - 如何根据显示值过滤 agGrid 中的行?
- perforce - 我们如何在 perforce 中签出文件的特定版本?
- java - Java中接口和类的继承
- python-3.x - 在硒测试中无法识别单击按钮
- f# - F#- 出现错误 HttpFs.Client : "code":"415","message":"Content type '' not supported"
- python - 在这个 python 脚本中,为什么它不像它想象的那样减去?
- python - 如何使用 spacy 提取包含特定模式的句子?
- selenium - 使用 serenity.properties 中的 appium、selenium 网格执行测试
- c++ - 通过直接函数调用将 std::promise 对象传递给函数
- ontology - 使用 gate.creole.ontology 包在本体中旅行