getApplicationBanner returns 空
getApplicationBanner returns null
我正在为设置框开发自定义的 android 启动器,并尝试获取电视应用程序的横幅(如下图所示)使用
packageInfo.applicationInfo.loadBanner(context.getPackageManager());
要么
context.getPackageManager().getApplicationBanner(packageName)
它适用于大多数应用程序,但其中一些应用程序 returns 结果为 null,例如 Google Play Games,尽管我可以获得图标(这是旁边没有文本的徽标)。
我使用的 api 正确吗?有没有办法以编程方式获取它?
来自getApplicationBanner方法的文档:
added in API level 20
public abstract Drawable getApplicationBanner
(String packageName)
Retrieve the banner associated with an application. Given the name of
the application's package, retrieves the information about it and
calls getApplicationIcon()
to return its banner. If the application
cannot be found, NameNotFoundException
is thrown.
您的函数还应在调用 getApplicationBanner
方法后调用 getApplicationIcon
到 return 它的横幅。
我也遇到了这个问题。应用程序开发人员未将横幅附加到包的原因是他们将横幅附加到 activity。
样本:
<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ru.tv1.android.tv">
......
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name="ru.kino1tv.android.tv.App" android:supportsRtl="true" android:theme="@style/AppTheme.Leanback">
<activity android:banner="@drawable/app_icon_banner" android:icon="@drawable/app_icon_banner" android:label="@string/app_name" android:logo="@drawable/app_icon_banner" android:name="ru.kino1tv.android.tv.ui.activity.MainActivity" android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
</activity>
......
</application>
</manifest>
每个包可以有几个启动活动。因此,您需要先尝试加载 activity 的横幅,然后如果是 null
则尝试加载包的横幅。
Intent AppsIntent = new Intent(Intent.ACTION_MAIN, null);
AppsIntent.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
List<ResolveInfo> apps = mPackageManager.queryIntentActivities(AppsIntent, 0);
for (ResolveInfo app : apps) {
Drawable banner = app.activityInfo.loadBanner(mPackageManager);
if (banner == null) {
banner = app.activityInfo.applicationInfo.loadBanner(mPackageManager);
}
}
我正在为设置框开发自定义的 android 启动器,并尝试获取电视应用程序的横幅(如下图所示)使用
packageInfo.applicationInfo.loadBanner(context.getPackageManager());
要么
context.getPackageManager().getApplicationBanner(packageName)
我使用的 api 正确吗?有没有办法以编程方式获取它?
来自getApplicationBanner方法的文档:
added in API level 20
public abstract Drawable
getApplicationBanner
(String packageName)Retrieve the banner associated with an application. Given the name of the application's package, retrieves the information about it and calls
getApplicationIcon()
to return its banner. If the application cannot be found,NameNotFoundException
is thrown.
您的函数还应在调用 getApplicationBanner
方法后调用 getApplicationIcon
到 return 它的横幅。
我也遇到了这个问题。应用程序开发人员未将横幅附加到包的原因是他们将横幅附加到 activity。
样本:
<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ru.tv1.android.tv">
......
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name="ru.kino1tv.android.tv.App" android:supportsRtl="true" android:theme="@style/AppTheme.Leanback">
<activity android:banner="@drawable/app_icon_banner" android:icon="@drawable/app_icon_banner" android:label="@string/app_name" android:logo="@drawable/app_icon_banner" android:name="ru.kino1tv.android.tv.ui.activity.MainActivity" android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
<intent-filter>
<action android:name="android.intent.action.SEARCH"/>
</intent-filter>
</activity>
......
</application>
</manifest>
每个包可以有几个启动活动。因此,您需要先尝试加载 activity 的横幅,然后如果是 null
则尝试加载包的横幅。
Intent AppsIntent = new Intent(Intent.ACTION_MAIN, null);
AppsIntent.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
List<ResolveInfo> apps = mPackageManager.queryIntentActivities(AppsIntent, 0);
for (ResolveInfo app : apps) {
Drawable banner = app.activityInfo.loadBanner(mPackageManager);
if (banner == null) {
banner = app.activityInfo.applicationInfo.loadBanner(mPackageManager);
}
}