version:1.6
fix: update:增加4:3适配
This commit is contained in:
@@ -15,7 +15,9 @@ import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.PowerManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
@@ -64,6 +66,32 @@ public class Utils {
|
||||
// return serial;
|
||||
// }
|
||||
|
||||
public static String getAndroiodScreenProperty(Context context) {
|
||||
Log.e("getAndroiodScreenProperty", "heightPixels:" + context.getResources().getDisplayMetrics().heightPixels);
|
||||
Log.e("getAndroiodScreenProperty", "widthPixels:" + context.getResources().getDisplayMetrics().widthPixels);
|
||||
Log.e("getAndroiodScreenProperty", "density:" + context.getResources().getDisplayMetrics().density);
|
||||
Log.e("getAndroiodScreenProperty", "densityDpi:" + context.getResources().getDisplayMetrics().densityDpi);
|
||||
|
||||
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
wm.getDefaultDisplay().getRealMetrics(dm);
|
||||
int width = dm.widthPixels; // 屏幕宽度(像素)
|
||||
int height = dm.heightPixels; // 屏幕高度(像素)
|
||||
float density = dm.density; // 屏幕密度(0.75 / 1.0 / 1.5)
|
||||
int densityDpi = dm.densityDpi; // 屏幕密度dpi(120 / 160 / 240)
|
||||
// 屏幕宽度算法:屏幕宽度(像素)/屏幕密度
|
||||
int screenWidth = (int) (width / density); // 屏幕宽度(dp)
|
||||
int screenHeight = (int) (height / density);// 屏幕高度(dp)
|
||||
|
||||
Log.e("getAndroiodScreenProperty", "屏幕宽度(像素):" + width);
|
||||
Log.e("getAndroiodScreenProperty", "屏幕高度(像素):" + height);
|
||||
Log.e("getAndroiodScreenProperty", "屏幕密度(0.75 / 1.0 / 1.5):" + density);
|
||||
Log.e("getAndroiodScreenProperty", "屏幕密度dpi(120 / 160 / 240):" + densityDpi);
|
||||
Log.e("getAndroiodScreenProperty", "屏幕宽度(dp):" + screenWidth);
|
||||
Log.e("getAndroiodScreenProperty", "屏幕高度(dp):" + screenHeight);
|
||||
return width + "×" + height;
|
||||
}
|
||||
|
||||
public static String getDeviceSN() {
|
||||
String serial = null;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user