问题描述
我正在尝试检索设备ID和imei编号以进行用户注册。但是代码将其返回为null。
internal fun getdeviceid(context: Context): String {
val telephonyManager = context.applicationContext.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
return when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> telephonyManager.imei
else -> telephonyManager.deviceid
}
}
internal fun getImei1(context: Context): String {
var imei1 = ""
if (ActivityCompat.checkSelfPermission(context,Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
imei1 = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> telephonyManager.getImei(0)
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> telephonyManager.getdeviceid(0)
else -> telephonyManager.deviceid
}
} else {
Toast.makeText(context,"Unable to retrieve IMEI1",Toast.LENGTH_SHORT).show()
}
return imei1
}
两者均返回null。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)