In my search I found that, the Android SDK provides no support for controlling HDMI port activities and handling HDMI output, as of now. Though certain device manufacturers like Motorola (don't know if any other does that too) provide API's for a little better control. Below are the links to two of them, out of which the dual screen one (which suits my requirement pretty close) is deprecated.
motorola hdmi status api
motorola hdmi dual screen api
Mirroring is the default behavior on connecting HDMI but, I want my app to run a binded service on HDMI out. This will allow the phone to perform any other tasks simultaneously, w/o disturbing my service running on the HDMI screen.
Can someone please suggest how can I go about it? Or if any other manufacturer provides similar flexibility as Motorola?
Create a Service class like so.
public class MultiDisplayService extends Service {
@Override
public void onCreate() {
super.onCreate();
DisplayManager dm = (DisplayManager)getApplicationContext().getSystemService(DISPLAY_SERVICE);
if (dm != null){
Display dispArray[] = dm.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
if (dispArray.length>0){
Display display = dispArray[0];
Log.e(TAG,"Service using display:"+display.getName());
Context displayContext = getApplicationContext().createDisplayContext(display);
WindowManager wm = (WindowManager)displayContext.getSystemService(WINDOW_SERVICE);
View view = LayoutInflater.from(displayContext).inflate(R.layout.fragment_main,null);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.TYPE_TOAST,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
wm.addView(view, params);
}
}
}
Start the service, perhaps in your Application class.
public class MultiDisplayApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
startService(new Intent(this, MultiDisplayService.class));
}
}
You will probably need more complex display add/remove logic based on DisplayManager.DisplayListener
mDisplayManager = (DisplayManager) this.getSystemService(Context.DISPLAY_SERVICE);
mDisplayManager.registerDisplayListener(this, null);
Using WindowManager.LayoutParams.TYPE_TOAST
requires no permissions but seems like a hack. WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
might be more reasonable, but requieres
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
in your AndroidManifest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With