Com*_*are 12 android android-displaymanager
在这个示例项目中,我MainActivity有代码在外部显示器上启动一个单独的活动,使用setLaunchDisplayId()on ActivityOptions:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
getSystemService(DisplayManager::class.java)
.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION)
.firstOrNull()
?.let { display ->
Intent(this, ExternalDisplayActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
.let { intent ->
ActivityOptions.makeBasic()
.setLaunchDisplayId(display.displayId)
.toBundle()
.let { opts ->
startActivity(intent, opts)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
ExternalDisplayActivity launches fine onto the external display. However; it shows up in portrait mode, not landscape. This occurs both using a real monitor and a simulated external display from Developer Options in Settings.
Strangely enough, this comes despite the fact that I have android:screenOrientation="landscape" on the ExternalDisplayActivity manifest entry and I request landscape at runtime:
class ExternalDisplayActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_external)
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
}
Run Code Online (Sandbox Code Playgroud)
landscape works if I use a Presentation and that older API, but I cannot figure out how to get landscape working with the setLaunchDisplayId() route.
| 归档时间: |
|
| 查看次数: |
316 次 |
| 最近记录: |