【发布时间】:2014-04-06 13:55:02
【问题描述】:
我最近在 android 市场上发布了我的第一个应用程序,并注意到如果用户在其 Play 商店应用程序中将“将图标添加到主屏幕”设置为 true,则在安装期间创建的快捷方式名称错误。
获取活动的标签,而不是应用程序标签上指定的字符串或意图过滤器上的标签。
如果用户手动创建快捷方式,则命名正确。
这是我的 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
任何想法为什么会发生这种情况以及如何避免它?
如果可能的话,我想避免将类别活动的标题更改为 app_name 的解决方案,然后以编程方式更改 onCreate 中的标题,因为我听说这会导致 app_name 在以编程方式设置要显示的标题。
EDIT1:我试图在尽可能小的环境中重新创建该问题,因此我创建了一个新的 android 项目并进行了必要的更改来说明该问题,然后我将其发布在 Google Play 上“测试 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:我刚刚注意到手动创建的快捷方式,如前所述,一开始是正确的名称,但在重新启动设备后,它们会得到错误的名称。
【问题讨论】:
-
我向 android 问题跟踪器提交了一份问题报告:code.google.com/p/android/issues/detail?id=68325,我将继续实施使用应用程序名称标记我的启动器活动的解决方法,然后在 onCreate 中更改标题,丑陋,但似乎没有其他人对此有任何问题,所以我猜这就是要走的路。
标签: android installation shortcut