Ivan Morgill..

5

我最终出来了.它正在使用S3和S4.它应该适用于任何4+ Android版本.

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

if (state) {

Log.d("HDMIListner", "BroadcastReceiver.onReceive() : Connected HDMI-TV");

Toast.makeText(ctxt, "HDMI >>", Toast.LENGTH_LONG).show();

} else {

Log.d("HDMIListner", "HDMI >>: Disconnected HDMI-TV");

Toast.makeText(ctxt, "HDMI DisConnected>>", Toast.LENGTH_LONG).show();

}

}

}

}

AndroidManifest.xml需要将其转换为应用程序标记:

这有助于我检测hdmi是连接还是断开,但在运行应用程序之前不知道hdmi是否已连接. (2认同)

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐