1、File -> Settings... -> Editor -> Inspections -> Serialization issues -> Serializable class without ‘serialVersionUID‘(选中)
2、进入实现了Serializable中的类,选中类名,Alt+Enter弹出提示,然后直接导入完成
在Android Studio中 获取到唯一标识的方法:
因为 TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE)
需要系统权限: permission.READ_PHONE_STATE 需要在androidManifest.xml中添加权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
在 Android6.0以上的版本中,即使添加了 这个权限,仍然要用户动态获取,如果 用户没有动态允许此权限开通,则此方法 仍然可以获取唯一标识。用来识别用户身份;
public class AppInfoUtil implements Serializable { /* * http://www.cnblogs.com/aspirant/p/7600015.html ==> this is the method of create serial Version UID * */ private static final long serialVersionUID = 211459722873093506L; // need the permission of permission.READ_PHONE_STATE ,if not permission then return UUID; public static String getIMEI(Context context) { String IMEI = null; try { TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE); IMEI = TelephonyMgr.getDeviceId(); } catch (Exception e) { e.printStackTrace(); IMEI = String.valueOf(serialVersionUID); } return IMEI; } public static String getVersionName(Activity activity) { // 获取packagemanager的实例 PackageManager packageManager = activity.getPackageManager(); // getPackageName()是你当前类的包名,0代表是获取版本信息 PackageInfo packInfo = null; try { packInfo = packageManager.getPackageInfo(activity.getPackageName(), 0); String version = packInfo.versionName; return version; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return "0"; } } }