Search code examples
androidbroadcastreceiverandroid-tv

BroadcastReceiver notification not sent for android.media.tv.action.INITIALIZE_PROGRAMS


Broadcast which should be sent to the application just after app is installed on TV is not received.

I declared BR in Manifest.xml:

<receiver
   android:name=".RunOnInstallReceiver"
   android:exported="true">
   <intent-filter>
     <action android:name="android.media.tv.action.INITIALIZE_PROGRAMS" />
     <category android:name="android.intent.category.DEFAULT" />
   </intent-filter>
</receiver>

I declared also:

<uses-feature
    android:name="android.software.leanback"
    android:required="true" />

RunOnInstallReceiver class is very simple:

public class RunOnInstallReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
     Log.v("RAMPS", "Broadcast received");
  }
}

I tried with nVidia Shield and Mi Box 3 - no success. Anyone had similar problem?


Solution

  • Are you side loading the application? INITIALIZE_PROGRAMS is only sent when the application is installed via the store.

    When side loading (installing from adb or android studio), you can trigger the intent with:

    adb shell am broadcast -a android.media.tv.action.INITIALIZE_PROGRAMS -n com.your.app.package/.YourReceiver

    Answer is from bullet #5 in Android developer guide for creating a channel on the home screen: https://developer.android.com/training/tv/discovery/recommendations-channel#creating_a_channel