因为这部分知识经常用到,因此整理一下,为了以后使用方便
1. 判断手机是否root
//判断手机是否root
public static boolean isRoot() {
String binPath = "/system/bin/su";
String xBinPath = "/system/xbin/su";
if (new File(binPath).exists() && isCanExecute(binPath)) {
return true;
}
if (new File(xBinPath).exists() && isCanExecute(xBinPath)) {
return true;
}
return false;
}
private static boolean isCanExecute(String filePath) {
java.lang.Process process = null;
try {
process = Runtime.getRuntime().exec("ls -l " + filePath);
BufferedReader in = new BufferedReader(new InputStreamReader(process.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 (process != null) {
process.destroy();
}
}
return false;
}
2. 获取MAC地址
/**
* 获取MAC地址
* 需添加权限<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
*/
public static String getMacAddress(Context context) {
String macAddress;
WifiManager wifi = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
macAddress = info.getMacAddress();
if (null == macAddress) {
return "";
}
macAddress = macAddress.replace(":", "");
return macAddress;
}
3. 是否有SD卡
/**
* 是否有SD卡
*/
public static boolean haveSDCard() {
return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
}
4. 判断设备是否是手机
/**
* 判断设备是否是手机
*/
public static boolean isPhone(Context context) {
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return telephony.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}
5.获取当前设备的IMIE
/**
* 获取当前设备的IMIE,需与上面的isPhone一起使用
*/
public static String getDeviceIMEI(Context context) {
String deviceId;
if (isPhone(context)) {
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
deviceId = telephony.getDeviceId();
} else {
deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
return deviceId;
}
6. 判断手机是否为64位的方法
public static boolean is64bitDevice() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return Build.SUPPORTED_64_BIT_ABIS.length > 0;
} else {
return false;
}
}
持续更新…