英文:
How to: Use DisplayManager to get displays and set a bool
问题
我的 Java 理解基本上是不存在的.. 我只真正理解 Dart。
然而,我需要使用 `DisplayManager` 和 `getDisplays()` 来设置一个布尔值。
我需要类似这样的代码(我知道这实际上不是真正的 Java,只是为了让别人理解):
DisplayManager displayManager = DisplayManager();
List<Display> displays = [];
boolean hasDisplays = false;
void _getDisplays(){
displays = DisplayManager.getDisplays();
}
void _displayBool(){
if(displays.length > 1){
hasDisplays = true;
} else {
hasDisplays = false;
}
}
如果有人可以向我展示在这种情况下该如何做类似的事情,那将是很棒的。
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
英文:
My understanding of Java is basically nonexistent .. I only really understand Dart.
However, I need to use DisplayManager
and getDisplays()
in order to set a boolean.
I need something like this (I know this isn't really java, it's just so someone can get an understanding):
DisplayManager displayManager = DisplayManager();
List<Display> displays = [];
bool hasDisplays = false;
void _getDisplays(){
displays = DisplayManager.getDisplays();
}
void _displayBool(){
if(displays.length > 1){
hasDisplays = true;
} else {
hasDisplays = false;
}
if someone could show me how the hell I'm supposed to do something like that, inside of this, it would be amazing
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
答案1
得分: 1
您需要使用context.getSystemService()
函数获取DisplayManager
。然后您可以使用displayManager.getDisplays()
函数获取显示器列表(Display[]
)。如果您想要知道列表中是否有一个或多个显示器,则将语句设置为布尔值。
DisplayManager displayManager = (DisplayManager) getApplicationContext().getSystemService(Context.DISPLAY_SERVICE);
Display[] displays = displayManager.getDisplays();
boolean hasDisplays = displays.length >= 1;
英文:
You need to get the DisplayManager
with the context.getSystemService()
function. Then you get the list of Displays (Display[]
) from the displayManager.getDisplays()
function. Then if you want to know if there are one or more displays in the list, set the statement to the boolean.
DisplayManager displayManager = (DisplayManager) getApplicationContext().getSystemService(Context.DISPLAY_SERVICE);
Display[] displays = displayManager.getDisplays();
boolean hasDisplays = displays.length >= 1;
答案2
得分: 0
好的,以下是您要翻译的代码部分:
class TestScreenCount {
public static void main(String[] args) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] allScreens = env.getScreenDevices();
System.out.println(Arrays.toString(allScreens));
}
}
这段代码会输出已连接的显示器,以我的情况为例(我有一个外部显示器和一个笔记本电脑屏幕):
[X11GraphicsDevice[screen=0], X11GraphicsDevice[screen=1]]
英文:
Well you can try this code:
class TestScreenCount {
public static void main(String[] args) {
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] allScreens = env.getScreenDevices();
System.out.println(Arrays.toString(allScreens));
}
}
This will output the connected displays, for my case (I have an external screen and a laptop screen):
[X11GraphicsDevice[screen=0], X11GraphicsDevice[screen=1]]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论