首页 > 移动平台 > 详细

JAVA,获取手机屏幕大小

时间:2021-07-22 10:54:36      阅读:22      评论:0      收藏:0      [点我收藏+]

效果如图,返回list:

技术分享图片

 

 

代码如下:

package com.java.app01;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class GetScreenSize {
    public static void main(String[] args) {
        ArrayList<String> screenSize = getScreenSize();
        System.out.println(screenSize);
    }

    public static ArrayList<String> getScreenSize() {
        Runtime runtime = Runtime.getRuntime();
        ArrayList<String> list = new ArrayList<>();
        try {
            Process wmSize = runtime.exec("adb shell wm size");
            InputStream inputStream = wmSize.getInputStream();
            InputStreamReader reader = new InputStreamReader(inputStream);
            BufferedReader bf = new BufferedReader(reader);
            String mark;
            StringBuilder buffer = new StringBuilder();
            while ((mark = bf.readLine()) != null) {
                buffer.append(mark);
            }
            String s = buffer.toString();
            for (String size : s.replaceAll("[^0-9]", ",").split(",")) {
                if (size.length() > 0)
                    list.add(size);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;

    }
}

 

JAVA,获取手机屏幕大小

原文:https://www.cnblogs.com/xiamaojjie/p/15041887.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!