android.media.tv.action.INITIALIZE_PROGRAMS 未发送 BroadcastReceiver 通知

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

应用程序安装到电视后立即发送给应用程序的广播收不到。

我在 Manifest.xml 中声明了 BR:

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

我还声明:

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

RunOnInstallReceiverclass很简单:

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

我试过 nVidia Shield 和 Mi Box 3 - 没有成功。有人遇到过类似的问题吗?

您是否正在加载应用程序? INITIALIZE_PROGRAMS 仅在通过商店安装应用程序时发送。

侧面加载时(从 adb 或 android studio 安装),您可以通过以下方式触发意图:

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

答案来自 Android 在主屏幕上创建频道的开发人员指南中的项目符号 #5:https://developer.android.com/training/tv/discovery/recommendations-channel#creating_a_channel

在我的例子中,如果你使用 product flavor 你应该触发:

adb shell am broadcast -a android.media.tv.action.INITIALIZE_PROGRAMS -n X/Y

X 是你的applicationID。 Y是你项目中广播接收文件的link。

示例您使用构建变体staging构建您的应用程序并且触发器是

adb shell am broadcast -a android.media.tv.action.INITIALIZE_PROGRAMS -n com.google.android.staging/com.google.android.tvhomescreenchannels.RunOnInstallReceiver

这是ApplicationId:

这是路径 RunOnInstallReceiver: