/**
* 判断手机是否root
*/
public static boolean isRoot() {
String binPath = "/system/bin/su";
String xBinPath = "/system/xbin/su";
if (new File(binPath).exists() && isCanExecute(binPath)) {
return true;
}
return new File(xBinPath).exists() && isCanExecute(xBinPath);
}
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;
}
//判断是否是模拟器
public boolean isEmulator(Context context) {
String url = "tel:" + "123456";
Intent intent = new Intent();
intent.setData(Uri.parse(url));
intent.setAction(Intent.ACTION_DIAL);
// 是否可以处理跳转到拨号的 Intent
boolean canResolveIntent = intent.resolveActivity(context.getPackageManager()) != null;
return Build.FINGERPRINT.startsWith("generic")
|| Build.FINGERPRINT.toLowerCase().contains("vbox")
|| Build.FINGERPRINT.toLowerCase().contains("test-keys")
|| Build.MODEL.contains("google_sdk")
|| Build.MODEL.contains("Emulator")
|| Build.SERIAL.equalsIgnoreCase("unknown")
|| Build.SERIAL.equalsIgnoreCase("android")
|| Build.MODEL.contains("Android SDK built for x86")
|| Build.MANUFACTURER.contains("Genymotion")
|| (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
|| "google_sdk".equals(Build.PRODUCT)
|| ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE))
.getNetworkOperatorName().toLowerCase().equals("android")
|| !canResolveIntent;
}
public static void showToast(Context context, int layooutId) {
Toast toastStart = new Toast(context);
toastStart.setGravity(Gravity.CENTER, 0, 0);
toastStart.setDuration(Toast.LENGTH_SHORT);
View view = LayoutInflater.from(context).inflate(layooutId, null, false);
toastStart.setGravity(Gravity.FILL, 0, 0);
toastStart.setView(view);
toastStart.show();
}