在这个示例项目中,我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 …
我正在尝试更改 Android 8.1 上主显示器的显示分辨率。我从内核收到一个事件(基于 EDID),告诉我需要更改模式。
然后我基本上做:
sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain));
status_t res = SurfaceComposerClient::setActiveConfig(display, new_mode);
Run Code Online (Sandbox Code Playgroud)
这会正确更新 SurfaceFlinger、显示 hal 和内核,但 windowmanager/display 不会更改分辨率,直到我运行:
wm size 1920x1080
wm density 240
Run Code Online (Sandbox Code Playgroud)
但是 wm 调用这些函数,这看起来有点太苛刻了,并且还将尺寸/密度存储在持久设置中:
public void setForcedDisplaySize(int displayId, int width, int height);
public void setForcedDisplayDensityForUser(int displayId, int density, int userId);
Run Code Online (Sandbox Code Playgroud)
我一直在查看 windowmanager/display 中的代码,但没有找到我应该用于此目的的 API。
有没有办法通知 windowmanager/display 有关 surfaceflinger 的更改,或者我错过了可以使用的 API?
我是否以错误的方式处理这个问题?有没有一种正确的方法可以改变主显示器的分辨率/模式,但我还没有找到?
android android-windowmanager surfaceflinger android-displaymanager
为了增强我的Android应用程序的安全性,我需要检测屏幕镜像。我已经实现了下面的源代码:
var display : DisplayManager = getSystemService(DISPLAY_SERVICE) as DisplayManager
var presentationdisplay= display.getDisplays(DISPLAY_CATEGORY_PRESENTATION).size
Toast.makeText(this, "disp size "+presentationdisplay, Toast.LENGTH_SHORT).show()
if(presentationdisplay>0) {
Toast.makeText(this, "your Mobile screen is shared by other app", Toast.LENGTH_SHORT).show()
}
Run Code Online (Sandbox Code Playgroud)
该代码能够检测 Screen Casting 以及 GoogleMeet、TeamViewer 的屏幕共享。但它没有检测到 MicrosoftTeams 和 Zoom 屏幕共享。我发现 MicrosoftTeams 和 Zoom 正在使用FLAG_PRIVATE,而FLAG_PRESENTATIONGoogleMeet、TeamViewer 仅使用FLAG_PRESENTATION. 我假设他们将其虚拟显示器保护为私有使用FLAG_PRIVATE。有什么方法可以检测屏幕镜像吗FLAG_PRIVATE?
android screenshot kotlin android-security android-displaymanager