Created
November 7, 2017 18:38
-
-
Save oleynikd/1065521ee3236a60b804ad063020021f to your computer and use it in GitHub Desktop.
Android TV HDMI plug/unplug event example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ua.youtv.testapp; | |
import android.app.Activity; | |
import android.content.BroadcastReceiver; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.content.IntentFilter; | |
import android.util.Log; | |
import static android.media.AudioManager.ACTION_HDMI_AUDIO_PLUG; | |
import static android.media.AudioManager.EXTRA_AUDIO_PLUG_STATE; | |
/* | |
* MainActivity class that loads {@link MainFragment}. | |
*/ | |
public class MainActivity extends Activity { | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
unregisterReceiver(eventReceiver); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
IntentFilter filter = new IntentFilter(); | |
filter.addAction(ACTION_HDMI_AUDIO_PLUG); | |
registerReceiver(eventReceiver, filter); | |
} | |
private BroadcastReceiver eventReceiver = new BroadcastReceiver() { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
// pause video | |
String action = intent.getAction(); | |
switch (action) { | |
case ACTION_HDMI_AUDIO_PLUG : | |
// EXTRA_AUDIO_PLUG_STATE: 0 - UNPLUG, 1 - PLUG | |
Log.d("MainActivity", "ACTION_HDMI_AUDIO_PLUG " + intent.getIntExtra(EXTRA_AUDIO_PLUG_STATE, -1)); | |
break; | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment