I need to receive the HDMI state events for my Android TV app.
I found this code in several places:
public class HdmiListener extends BroadcastReceiver {
private static String HDMIINTENT = "android.intent.action.HDMI_PLUGGED";
@Override
public void onReceive(Context ctxt, Intent receivedIt) {
String action = receivedIt.getAction();
if (action.equals(HDMIINTENT)) {
boolean state = receivedIt.getBooleanExtra("state", false);
}
}
}
with this in manifest:
<receiver android:name="[package].HdmiListener" >
<intent-filter>
<action android:name="android.intent.action.HDMI_PLUGGED" />
</intent-filter>
</receiver>
but it does not work. The broadcast receiver never gets triggered.
I did some digging through AOSP and other projects and were able to come up with a more complete version of the manifest entry:
<permission android:name="android.permission.TV_INPUT_HARDWARE"
android:protectionLevel="signatureOrSystem"
tools:ignore="SignatureOrSystemPermissions" />
<permission android:name="android.permission.CAPTURE_TV_INPUT"
android:protectionLevel="signatureOrSystem"
tools:ignore="SignatureOrSystemPermissions" />
<receiver android:name="[package].HdmiListener"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.HDMI_PLUG" />
<action android:name="android.intent.action.HDMI_PLUGGED" />
<action android:name="android.intent.action.TVOUT_PLUG" />
<action android:name="android.media.action.HDMI_AUDIO_PLUG" />
</intent-filter>
</receiver>
but is still does not work :-(
So, my question is - did anybody get this to actually work? Or is it a system-level-only feature, as the permissions would suggest?