Created
August 8, 2018 14:22
-
-
Save crgarridos/455a004770886cfe26acb7fdc64f019d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequiresPermission("android.permission.READ_PHONE_STATE") | |
public static String getDeviceId(Context context) { | |
String androidId = Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID); | |
if (androidId != null) | |
return androidId; | |
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); | |
if (tm != null) { | |
if (tm.getDeviceId() != null) | |
return tm.getDeviceId(); | |
else | |
return tm.getSimSerialNumber(); | |
} else | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment