Search code examples
androidandroid-tvandroid-launcher

getApplicationBanner returns null


I am working on a customized android launcher for a setupbox and trying to get the banner of the tv applications (the ones seen in the image below) using packageInfo.applicationInfo.loadBanner(context.getPackageManager()); OR context.getPackageManager().getApplicationBanner(packageName)

Android tv apps It is working for most apps, however some of them returns null as a result, For example Google Play Games, although i can get the icon (which is the logo without the text beside it).

Am I using the correct api? Is there anyway to get it programmatically?


Solution

  • I am also having that problem. The reason app developers didn`t attach banner to package is because they attach banner to activity.

    Sample:

    <?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>
    

    Every package can have few launch activities. So, you need first try to load banner for activity, and then if it's null try to load the banner for package.

    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);
        }
    }