TelephonyManager.getDeviceId()返回null 解决办法
在android开发发现TelephonyManager.getDeviceId()在权限允许的情况下取得返回值也为null,解决方法如下:
public static String getDeviceId(Context context) {
String mDeviceId;
TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (mTelephony.getDeviceId() != null) {
mDeviceId = mTelephony.getDeviceId();
} else {
//android.provider.Settings;
mDeviceId = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
}
return mDeviceId;
}