我最近在 Android 市场上发布了我的第一个应用程序,并注意到如果用户在他们的 Play 商店应用程序中将“将图标添加到主屏幕”设置为 true,则在安装过程中创建的快捷方式名称有误。
它不是应用程序标签上指定的字符串或 Intent 过滤器上的标签,而是获取 Activity 的标签。
如果用户手动创建快捷方式,则命名正确。
这是我的 AndroidManifest.xml 的摘录:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dosolves.gym"
android:versionCode="2"
android:versionName="1.1" >
...
<application
android:name="com.dosolves.gym.app.GymApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.dosolves.gym.app.category.gui.CategoriesActivity"
android:label="@string/categories" >
<intent-filter android:label="@string/app_name" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</application>
</manifest>
我看过其他关于类似问题的问题,例如: How to set different label for launcher rather than activity title? 但我的问题只发生在上面指定的地方,手动创建的快捷方式和启动器/程序菜单中的图标都有正确的名称。
我所有快捷方式的所需名称在以下位置指定:@string/app_name 我不想要的是:@string/categories
知道为什么会发生这种情况以及如何避免这种情况吗?
如果可能的话,我想避免将我的类别 Activity 的标题更改为 app_name 然后以编程方式更改 onCreate 中的标题的解决方案,因为我听说这会导致 app_name 在以编程方式设置要显示的标题。
EDIT1: 我试图在尽可能小的环境中重现该问题,因此我创建了一个新的 android 项目并进行了必要的更改以说明该问题,然后我将其作为“测试 App Store 快捷方式”。可以从以下网址下载:https://play.google.com/store/apps/details?id=com.dosolves.testappstoreshortcutname或者搜索我的名字“David Svedberg”。如果您想重现该问题,请务必更改 Android 设备上 Play 商店应用中的设置,以自动在主屏幕上创建快捷方式。
完整显示的最少应用:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dosolves.testappstoreshortcutname"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/right_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.dosolves.testappstoreshortcutname.MainActivity"
android:label="@string/wrong_name" >
<intent-filter android:label="@string/right_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
和 string.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="right_name">Right Name</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="wrong_name">Wrong Name</string>
</resources>
EDIT2:我刚刚注意到,如前所述,手动创建的快捷方式最初给出了正确的名称,但在设备重新启动后,它们得到了错误的名称。
最佳答案
我刚遇到同样的问题,最终将应用程序名称设置为启动器 Activity 标签,然后使用 setTitle
设置实际 Activity 名称。如果您在 super.onCreate
和 setContentView
之前调用 setTitle
,应用名称将不会在 Activity 名称之前显示一小段时间。我还认为这是一个 hacky 解决方法,想知道为什么我无法在网络上找到有关此问题的更多信息。
关于android - 为什么在我的应用程序安装过程中出现错误的快捷方式名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22894973/