maj

30

How to use the hidden HDMI API [tutorial]

HDMI-tutorial
HDMI-tutorial

Are you working on an Android™ app that you’d like users to experience on an external device like a TV or monitor? If your Xperia™ smartphone (or other Android™ device) has an HDMI port, then your app should detect when it’s plugged into a powered high-definition screen to ensure the display is rendered properly on the larger screen. This quick tutorial includes some code that shows you how. Read more after the jump.

HDMI tutorial image 2

Phone content shown on a TV using the HDMI connection.

A number of Sony and Sony Ericsson phones (Xperia™ arc, Xperia™ arc S, Xperia™ neo, Xperia™ pro, Xperia ion™ and Xperia™ S) feature a High Definition Multimedia Interface (HDMI) port. When you connect an HDMI cable, the screen content shown on the device is automatically mirrored to the larger screen. In some cases, maybe the app developer intentionally wants to prevent the HDMI port becoming active, if the content is only meant for the handset screen. But if you want your app to receive and render content via the HDMI port, your app must be registered to receive HDMI port status changes.

An application can detect if the device is connect via an HDMI connector by listening to the broadcast intent:

"com.sonyericsson.intent.action.HDMI_EVENT"

This intent carries an extra parameter that contains information regarding if HDMI is in use. This extra parameter is named:

"com.sonyericsson.intent.extra.HDMI_STATE"

The supported HDMI states are: “HDMI_OFF” and “HDMI_IN_USE.”

In this case, you will need to prepare a BroadcastReceiver listening to that event, as shown by the following sample code:

In AndroidManifest.xml:

<receiver android:name=".HdmiListener">
<intent-filter>
<action android:name="com.sonyericsson.intent.action.HDMI_EVENT" />
</intent-filter>
</receiver>

In the source code of the BroadcastReceiver:

public class HdmiListener extends BroadcastReceiver {
static String HDMIAPPEXTRA = "abrisHdmiExtraParameter";


// Just a name for my launched activity
private static String HDMIINTENT = "com.sonyericsson.intent.action.HDMI_EVENT";
private  static final String EXTRA_HDMI_STATE =
"com.sonyericsson.intent.extra.HDMI_STATE";

@Override
public void onReceive(Context ctxt, Intent receivedIt) {
String action = receivedIt.getAction();
if (action.equals(HDMIINTENT)){
String extras = receivedIt.getStringExtra(EXTRA_HDMI_STATE);
Intent it = new Intent(ctxt,HdmiFromIntent.class);
it.putExtra(HDMIAPPEXTRA, extras);
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctxt.startActivity(it);

//Do whatever you want to do – preferably
//hand an intent to a service instead of
//launching an activity – in this case a UI was
//desired for demo purpose.
}
}

}

It’s as easy as that. So if you haven’t yet bothered ensuring that your Android™ app detects HDMI, just remember that several Xperia™ smartphones, and other Android phone manufacturers, have an HDMI port. Including HDMI connection is a small fix for your app that could go a long way, and might help your app stand out from similar apps missing the feature. Interested in trying out the HDMI API? Let us know how it goes and if you have any questions.

More information

Źródło: How to use the hidden HDMI API [tutorial]



Category: Sony Ericsson | Tags: None

Related Posts




You must be logged in to post a comment.

Name (wymagane)

Email (wymagane)

Witryna internetowa

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Share your wisdom

wielkoformatowe wydruki Lublin kolorowe wielkoformatowe skanowanie kolorowe skanowanie w lublinie skanowanie lublin skanowanie Lublin skanowanie lublin wielki format w lublinie skanowanie lublin skanowanie dokumentów lublin wizytówki w godzinę wizytówki Lublin wizytówki od ręki