三个点,Display-addSecondary display
方案一
通过Presentation来实现,他是一个Dialog(context,display)
val displayService = getSystemService(DISPLAY_SERVICE) as DisplayManager
val displays = displayService.displays
for (display in displays){
Log.i("alic",display.toString())
}
if (displays.size > 1){
Log.i("alic show",displays[1].toString())
var p:Presentation = DifferentDisplay(this, displays[1])
p.show()
}
package com.example.myapplication;
import android.app.Presentation;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
public class DifferentDisplay extends Presentation {
public DifferentDisplay(Context outerContext, Display display) {
super(outerContext, display);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.different_display);
}
}
方案二
使用ActivityOptions设置activity显示在哪个屏幕上 launchDisplayId
val options = ActivityOptions.makeBasic()
options.launchDisplayId = 2
val secondIntent = Intent()
val cn = ComponentName("com.example.myapplication","com.example.myapplication.SecondActivity")
secondIntent.component = cn
secondIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(secondIntent,options.toBundle())
方案三
adb shell am start -n 包名+Activity
adb shell am start -n com.example.myapplication/com.example.myapplication.MainActivity --display 2