在我的搜索中我发现,到目前为止,Android SDK还不支持控制HDMI端口活动和处理HDMI输出。虽然某些设备制造商,如摩托罗拉(不知道是否有其他制造商也这样做)提供了API,以便更好地控制。下面是其中两个的链接,其中的双屏幕链接(它非常适合我的要求)是弃用的。
motorola hdmi status api
motorola hdmi dual screen api
镜像是连接HDMI的默认行为,但我希望我的应用程序在HDMI输出端运行绑定的服务。这将允许手机同时执行任何其他任务,而不会干扰我在HDMI屏幕上运行的服务。
有人能建议一下我该怎么做吗?或者,是否有其他制造商提供了与摩托罗拉类似的灵活性?
发布于 2015-08-19 03:56:58
像这样创建一个Service类。
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);
}
}
}启动服务,可能是在Application类中。
public class MultiDisplayApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
startService(new Intent(this, MultiDisplayService.class));
}
}您可能需要更复杂的基于DisplayManager.DisplayListener的显示添加/删除逻辑
mDisplayManager = (DisplayManager) this.getSystemService(Context.DISPLAY_SERVICE);
mDisplayManager.registerDisplayListener(this, null);使用WindowManager.LayoutParams.TYPE_TOAST不需要权限,但看起来像是一种技巧。WindowManager.LayoutParams.TYPE_SYSTEM_ALERT可能更合理,但请求者
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />在你的AndroidManifest里。
https://stackoverflow.com/questions/10822097
复制相似问题