创建实例
package com.example.multiscreen;
import android.app.Presentation;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
public class SecondaryScreenPresentation extends Presentation {
private Context context;
public SecondaryScreenPresentation(Context outerContext, Display display) {
super(outerContext, display);
this.context = outerContext;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_layout);
}
}
创建Activity
package com.example.multiscreen;
import android.app.Activity;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import com.alibaba.fastjson.JSON;
//多屏幕
public class MainActivity extends Activity {
private SecondaryScreenPresentation secondaryScreenPresentation;
private DisplayManager displayManager;//屏幕管理器
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initVideo();
}
private void initVideo() {
if (displayManager == null) {
displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
Display[] displays = displayManager.getDisplays();//获取窗口
Log.d("当前屏幕信息:", JSON.toJSON(displayManager.getDisplays()).toString());
if (displays.length > 1) {
secondaryScreenPresentation = new SecondaryScreenPresentation(MainActivity.this, displays[1]);// displays[1]是副屏
secondaryScreenPresentation.show();//显示指定屏幕
}
}
}
}
运行效果