我试图加载与当前的活动和/或在清单中定义其父应用程序相关的标志。该技术已成功地在工作负载与两个相关联的标题和图标,但标志总是返回空
或0。
I am trying to load the logo associated with the current activity and/or its parent application from the definition in the manifest. This technique has already worked successfully on loading the title and icon associated with both, but the logo is always returning null
or 0.
下面是我用工作清单中的相关信息:
Here is the relevant info from the manifest I am working with:
<application
android:icon="@drawable/ic_launcher"
android:logo="@drawable/ad_logo"
android:label="@string/app_name"
android:hardwareAccelerated="true">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:logo="@drawable/ad_logo">
使用活动
是上述定义的活动的一个实例,我曾尝试下面的(结果注解内联):
With activity
being an instance of the above defined activity, I have tried the following (results annotated inline):
PackageManager pm = activity.getPackageManager();
ComponentName cn = activity.getComponentName();
ApplicationInfo ai = activity.getApplicationInfo();
//ACTIVITY LABEL: Works
pm.getActivityInfo(cn, PackageManager.GET_ACTIVITIES).loadLabel(pm);
//APPLICATION LABEL: Works
ai.loadLabel(pm);
//APPLICATION LABEL: Works
pm.getApplicationLabel(ai);
//ACTIVITY ICON: Works
pm.getActivityInfo(cn, PackageManager.GET_ACTIVITIES).loadIcon(pm);
//ACTIVITTY ICON: Works
pm.getActivityIcon(cn);
//APPLICATION ICON: Works
pm.getApplicationIcon(ai);
//APPLICATION ICON: Works
ai.loadIcon(pm);
//ACTIVITY LOGO: Does not work
pm.getActivityInfo(cn, PackageManager.GET_ACTIVITIES).loadLogo(pm);
//ACTIVITY LOGO: Does not work
pm.getActivityInfo(cn, PackageManager.GET_ACTIVITIES).logo
//ACTIVITY LOGO: Does not work
pm.getActivityLogo(cn);
//APPLICATION LOGO: Does not work
pm.getApplicationLogo(ai);
//APPLICATION LOGO: Does not work
pm.getApplicationLogo(activity.getApplication().getPackageName());
//APPLICATION LOGO: Does not work
ai.loadLogo(pm);
//APPLICATION LOGO: Does not work
pm.getApplicationInfo(ai.packageName, 0).loadLogo(pm);
//APPLICATION LOGO: Does not work
ai.logo;
有谁知道如何正确地加载标识为这些目标的一个或两个?
Does anyone know how to properly load the logo for either or both of these targets?
修改的: 徽标支持需要API级别9.我正在测试的设备仿真器和物理设备的所有乳宁API级别10。这code将不会被3.0 +执行。
edit: Logo support requires API level 9. The devices I am testing on are emulators and physical devices all runing API level 10. This code will never be executed on 3.0+.
从我的测试中,你的code可以正常工作的蜂窝设备上运行,而不是在一个姜饼或以下的设备。这似乎暗示着安卓标志
的功能,虽然present在API 8级,是不正确的底层平台来实现。也就是说,一个级别8-10设备上的同一个应用程序的apk不保留标志属性,但一个等级11的设备一样。这意味着这个问题是不与code或AndroidManifest.xml中,但与平台
From my tests, your code works properly running on a Honeycomb device, but not on a Gingerbread or below device. That seems to imply that the android:logo
functionality, although present in API Level 8, is not implemented correctly in the underlying platform. That is, the same application apk on a Level 8-10 device is not retaining the logo attribute, but a Level 11 device does. That means the problem is not with the code or the AndroidManifest.xml, but with the platform.