Guest User

Untitled

a guest
Sep 14th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. private String getIMEINumber() {
  2. String IMEINumber = "";
  3. if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
  4. TelephonyManager telephonyMgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
  5. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  6. IMEINumber = telephonyMgr.getImei(0);
  7. } else {
  8. IMEINumber = telephonyMgr.getDeviceId();
  9. }
  10. }
  11. return IMEINumber;
  12. }
  13.  
  14.  
  15.  
  16.  
  17.  
  18. public static String getUniqueIMEIId(Context context) {
  19. try {
  20. TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  21. if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
  22. // TODO: Consider calling
  23. // ActivityCompat#requestPermissions
  24. // here to request the missing permissions, and then overriding
  25. // public void onRequestPermissionsResult(int requestCode, String[] permissions,
  26. // int[] grantResults)
  27. // to handle the case where the user grants the permission. See the documentation
  28. // for ActivityCompat#requestPermissions for more details.
  29. return "";
  30. }
  31. String imei = telephonyManager.getImei();
  32. Log.e("imei", "=" + imei);
  33. if (imei != null && !imei.isEmpty()) {
  34. return imei;
  35. } else {
  36. return android.os.Build.SERIAL;
  37. }
  38. } catch (Exception e) {
  39. e.printStackTrace();
  40. }
  41. return "not_found";
  42. }
Add Comment
Please, Sign In to add comment