daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Feb 18th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class DeviceUtils {
  2.  
  3.     public static String createUniqueResource(String resource) {
  4.         String res = String.format("%s_%s", resource, getDeviceUuid());
  5.         Timber.d("Resource %s", res);
  6.         return res;
  7.     }
  8.  
  9.     public static String getDeviceUuid() {
  10.         String uuid = UserPrefUtils.getString(AssistantApp.getContext(), UserPrefUtils.KEY_DEVICE_ID, null);
  11.         if (uuid != null) {
  12.             return uuid;
  13.         }
  14.         uuid = UUID.randomUUID().toString();
  15.         UserPrefUtils.putString(AssistantApp.getContext(), UserPrefUtils.KEY_DEVICE_ID, uuid);
  16.         return uuid;
  17.     }
  18.  
  19.     @SuppressLint("HardwareIds")
  20.     public static String generateDeviceIdentifier() {
  21.         String androidId = Settings.Secure.getString(
  22.                 AssistantApp.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
  23.  
  24.         if (androidId == null || androidId.length() == 0){
  25.             Timber.e("No ANDROID_ID! Generated a[32]");
  26.             return new String(new char[32]).replace('\0', 'a');
  27.         }
  28.  
  29.         StringBuilder androidIdBuilder = new StringBuilder(androidId);
  30.         while (androidIdBuilder.length() < 32) androidIdBuilder.append(androidId);
  31.         return androidIdBuilder.toString().substring(0, 32);
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top