我想记录用户实验的所有内容。但是我也想登录安卓手机设备ID,哪个手机品牌,什么是应用程序版本...像这样的东西。
Firebase Analythics 和 Appsee 就是这样做的。我从哪里开始?
编辑:
想想我会写一个SDK,有了这个SDK可以学习一切。
public String getDeviceName () {
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;
if (model.startsWith (manufacturer)) {
return capitalize (model);
}
else {
return capitalize (manufacturer) + " " + model;
}
}
public static int getAppVersion () {
try {
PackageInfo packageInfo = MainApplication.getContext ().getPackageManager ()
.getPackageInfo (MainApplication.getContext ().getPackageName (), 0);
return packageInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
// should never happen
throw new RuntimeException ("Could not get package name: " + e);
}
}
这是获取设备属性代码的示例
public static String getAPIlevel() {
return "Android API :" + Build.VERSION.SDK_INT;
}
public static String getDeviceName() {
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;
if (model.startsWith(manufacturer)) {
return SubUtils.capitalize(model);
} else {
return SubUtils.capitalize(manufacturer) + " " + model;
}
}
public static String getDeviceVersion(Context activity) {
String v;
try {
v = activity.getApplication().getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
return v.replace("-staging", "");
} catch (PackageManager.NameNotFoundException e) {
return null;
}
}
@SuppressLint("HardwareIds")
public static String getUDID(Context activity) {
if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
String tmDevice = "" + tm.getDeviceId();
String tmSerial = "" + tm.getSimSerialNumber();
String androidId = "" + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
return deviceUuid.toString();
} else {
return Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
}
}
或
您可以使用AndroidCodeUtils获取更完整的设备访问信息