First, screen resolution
Display display = Getwindowmanager (). Getdefaultdisplay ();
Point size = new Point ();
Display.getsize (size);
int width = size.x;
int height = size.y;
Or:
Displaymetrics metrics = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (metrics);
int width = metrics.widthpixels;
int height = Metrics.heightpixels
The above code is to be used in cases where it can be obtained, Activity
and if it is not available Activity
, you can use the code:
WindowManager wm = (WindowManager) context.getsystemservice (context.window_service);
Display display = Wm.getdefaultdisplay ();
Point point = new Point ();
Display.getsize (point);
int width = point.x;
int height = Point.y;
Second, screen size
Displaymetrics dm = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (DM);
int width=dm.widthpixels;
int height=dm.heightpixels;
int dens=dm.densitydpi;
Double wi= (double) width/(double) dens;
Double hi= (double) height/(double) dens;
Double x = Math.pow (wi,2);
Double y = Math.pow (hi,2);
Double screeninches = math.sqrt (x+y);
Again, the code above needs to be able to get an activity.
Third, get the app name
public static string Getappname {
string appName = "";
try {
Packagemanager Packagemanager = Context.getpackagemanager ();
ApplicationInfo applicationinfo = Packagemanager.getapplicationinfo (Context.getpackagename (), 0);
AppName = (String) Packagemanager.getapplicationlabel (applicationinfo);
} catch (Packagemanager.namenotfoundexception e) {
e.printstacktrace ();
}
return appName;
}
Iv. acquiring equipment Manufacturer and equipment name information
Device manufacturer
String brand = Build.brand;
Device name
String model = Build.model;
Get Deviceid,sim and IMSI
Telephonymanager TM = (Telephonymanager) context.getsystemservice (context.telephony_service);
String deviceId = Tm.getdeviceid ();
String sim = Tm.getsimserialnumber ();
String IMSI = (telephonymanager) getsystemservice (context.telephony_service). Getsubscriberid ();
Note that you need to AndroidManifest
add permissions in
<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
V. Getting network status
public static string Getapntype {//Result return value String NetType = "Nono_connect"; Get all connection management objects on the phone Connectivitymanager manager = (Connectivitymanager) context.getsystemservice (context.connectivity_
SERVICE);
Gets the Networkinfo object networkinfo networkinfo = Manager.getactivenetworkinfo ();
Networkinfo object is null to represent no network if (Networkinfo = null) {return nettype;
//Otherwise the Networkinfo object is not NULL to get the type int ntype = Networkinfo.gettype () of the networkinfo;
if (ntype = = Connectivitymanager.type_wifi) {//wifi NetType = "WIFI";
else if (ntype = = connectivitymanager.type_mobile) {int nsubtype = Networkinfo.getsubtype ();
Telephonymanager Telephonymanager = (telephonymanager) context.getsystemservice (Context.telephony_service);
4G if (nsubtype = Telephonymanager.network_type_lte &&!telephonymanager.isnetworkroaming ()) {
NetType = "4G"; else if (Nsubtype = Telephonymanager.network_type_umts | | nsubtype = = Telephonymanager.neTWORK_TYPE_HSDPA | |
Nsubtype = = Telephonymanager.network_type_evdo_0 &&!telephonymanager.isnetworkroaming ()) {NetType = "3G"; 2G Mobile and Unicom 2G for GPRS or Egde, telecom 2G for CDMA} else if (Nsubtype = = Telephonymanager.network_type_gprs | | nsubtype = = Teleph Onymanager.network_type_edge | |
Nsubtype = = Telephonymanager.network_type_cdma &&!telephonymanager.isnetworkroaming ()) {NetType = "2G";
else {NetType = "2G";
} return NetType; }
Vi. determining whether the device is root
There are many ways to judge on the Internet, but some will be prompted to get permission on the interface window, here is a way to determine whether the device is root without a window:
/** judge whether the phone is root, does not eject the root request box <br/>/* public static Boolean isRoot () {String binpath =
"/system/bin/su";
String Xbinpath = "/system/xbin/su";
if (new File (BinPath). Exists () && isexecutable (BinPath)) return true;
if (new File (Xbinpath). Exists () && isexecutable (Xbinpath)) return true;
return false;
private static Boolean isexecutable (String filePath) {Process p = null;
try {p = runtime.getruntime (). EXEC ("ls-l" + FilePath);
Gets the return content bufferedreader in = new BufferedReader (New InputStreamReader (P.getinputstream ()));
String str = in.readline ();
if (str!= null && str.length () >= 4) {char flag = Str.charat (3);
if (flag = = ' s ' | | flag = = ' x ') return true;
} catch (IOException e) {e.printstacktrace ();
finally {if (P!= null) {P.destroy ();
return false; }
Vii. Summary
The above is about getting Android devices all kinds of information, this article for you to develop the Android app has a certain reference value, hope to be helpful to everyone, if you have questions you can message exchange.