背景:最近一个项目希望有评论功能,而又不希望添加繁琐的注册登录模块。
做法:寻找针对每台手机的唯一串号,保存下来作为用户的唯一标示。
Context context = getWindow().getContext();
TelephonyManager telephonemanage = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try{
Toast.makeText(this, "MIEI码为:"+telephonemanage.getDeviceId(), 1000).show();
}
catch(Exception e){
Log.i("error", e.getMessage());
}
权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>