sdf
This commit is contained in:
78
app/src/main/java/utils/MyPhoneValue.java
Normal file
78
app/src/main/java/utils/MyPhoneValue.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
|
||||
public class MyPhoneValue {
|
||||
|
||||
public static String getMacAddress="";
|
||||
|
||||
public static int getDecorHeight(Context context){
|
||||
Rect frame = new Rect();
|
||||
Activity aty=(Activity) context;
|
||||
aty.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
|
||||
int statusBarHeight = frame.top;
|
||||
return statusBarHeight;
|
||||
}
|
||||
public static int getScreenHeight(Context context){
|
||||
Activity aty=(Activity)context;
|
||||
DisplayMetrics metric = new DisplayMetrics();
|
||||
aty.getWindowManager().getDefaultDisplay().getMetrics(metric);
|
||||
int height = metric.heightPixels;
|
||||
|
||||
return height;
|
||||
}
|
||||
public static int getScreeWidth(Context context){
|
||||
Activity aty=(Activity)context;
|
||||
DisplayMetrics metric = new DisplayMetrics();
|
||||
aty.getWindowManager().getDefaultDisplay().getMetrics(metric);
|
||||
int width = metric.widthPixels;
|
||||
return width;
|
||||
}
|
||||
|
||||
public static String getSdkVersion() {
|
||||
return android.os.Build.VERSION.RELEASE;
|
||||
}
|
||||
public static int[] getSDKVersion() {
|
||||
String a= android.os.Build.VERSION.RELEASE;//4.0.4
|
||||
String[] m=a.split("\\.");//用点分开必须加双斜杠
|
||||
int[] n=new int[m.length];
|
||||
for (int i=0;i<m.length;i++){
|
||||
n[i]=Integer.parseInt(m[i]);
|
||||
}
|
||||
return n;}
|
||||
public static int getStatusBarHeight(Context context) {
|
||||
Class<?> c = null;
|
||||
|
||||
Object obj = null;
|
||||
|
||||
Field field = null;
|
||||
|
||||
int x = 0, sbar = 0;
|
||||
|
||||
try {
|
||||
|
||||
c = Class.forName("com.android.internal.R$dimen");
|
||||
|
||||
obj = c.newInstance();
|
||||
|
||||
field = c.getField("status_bar_height");
|
||||
|
||||
x = Integer.parseInt(field.get(obj).toString());
|
||||
|
||||
sbar = context.getResources().getDimensionPixelSize(x);
|
||||
|
||||
} catch (Exception e1) {
|
||||
|
||||
e1.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
return sbar;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user