获取APP版本号
//添加权限
public String getVersion(Activity activity) {
try {
PackageManager manager = activity.getPackageManager();
PackageInfo info = manager.getPackageInfo(activity.getPackageName(), 0);
String version = info.versionName;
return version;
} catch (Exception e) {
e.printStackTrace();
return "找不到版本号";
}
}
获取手机操作系统
Settings.System.ANDROID_ID
获取手机品牌
Build.BRAND
获取设备id
public static String getDeviceId(Context context) {
String deviceId = "";
try {
if (Build.VERSION.SDK_INT < 29) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (tm != null) {
if (TextUtils.isEmpty(tm.getDeviceId()) == false)
deviceId = tm.getDeviceId();
else
deviceId = Settings.Secure.getString(context.getApplicationContext().getContentResolver(),
Settings.Secure.ANDROID_ID);
} else
deviceId = Settings.Secure.getString(context.getApplicationContext().getContentResolver(),
Settings.Secure.ANDROID_ID);
} else
deviceId = Settings.Secure.getString(context.getApplicationContext().getContentResolver(),
Settings.Secure.ANDROID_ID);
} catch (Exception e) {
e.printStackTrace();
}
return deviceId;
}