判断SD卡是否存在
/**
* 判断SD卡是否存在
*/
public static boolean sdState(Context context) {
String SDState = Environment.getExternalStorageState();
if (SDState.equals(Environment.MEDIA_MOUNTED)) {
return true;
} else {
Toast.makeText(context, "内存卡不存在", Toast.LENGTH_LONG).show();
return false;
}
}
获取当前应用版本号
/**
* 获取当前应用版本号
*/
public static int getVersion(Context context) {
PackageManager pm = context.getPackageManager();
try {
PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
return packageInfo.versionCode;
} catch (NameNotFoundException e) {
return 0;
}
}
获取当前应用版本名称
/**
* 获取当前应用版本名称
*/
public static String getVersionName(Context context) {
PackageManager pm = context.getPackageManager();
try {
PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
return packageInfo.versionName;
} catch (NameNotFoundException e) {
return "0.0";
}
}
获取设备ID
/**
* 获取设备ID
*/
public static String getDeviceId(Context context) {
TelephonyManager mTm = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
if (mTm != null) {
return mTm.getDeviceId();
}
return "";
}