import java.io.UnsupportedEncodingException;import java.util.UUID;import com.vtion.ym.util.Constant;import android.content.Context;import android.content.SharedPreferences;import android.provider.Settings.Secure;import android.telephony.TelephonyManager;public class DeviceUuidFactory {    public static final String PREFS_FILE = "device_id.xml";    public static final String PREFS_DEVICE_ID = "device_id";    public static UUID uuid;   public static void DeviceUuidFactory(Context context) {       if( uuid ==null ) {            synchronized (DeviceUuidFactory.class) {                if( uuid == null) {                    final SharedPreferences prefs = context.getSharedPreferences( PREFS_FILE, 0);                    final String id = prefs.getString(PREFS_DEVICE_ID, null );                   if (id != null) {                        // Use the ids previously computed and stored in the prefs file                        uuid = UUID.fromString(id);                        System.out.println("【设备号测试】uuid@-->" + uuid);                        Constant.DEVICE_ID = uuid+"";                   } else {                       final String androidId = Secure.getString(                               context.getContentResolver(), Secure.ANDROID_ID);                       System.out.println("【设备号测试】androidId-->" + androidId);                        // Use the Android ID unless it's broken, in which case fallback on deviceId,                        // unless it's not available, then fallback on a random number which we store                        // to a prefs file                        try {                            if (!"9774d56d682e549c".equals(androidId)) {                                uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8"));                            } else {                                final String deviceId = ((TelephonyManager) context.getSystemService(                                         Context.TELEPHONY_SERVICE )).getDeviceId();                                uuid = deviceId!=null ? UUID.nameUUIDFromBytes(                                        deviceId.getBytes("utf8")) : UUID.randomUUID();                                        System.out.println("【设备号测试2】uuid-->" + uuid);                            }                        } catch (UnsupportedEncodingException e) {                            throw new RuntimeException(e);                        }                        System.out.println("【设备号测试】uuid.toString()-->" + uuid.toString());                        Constant.DEVICE_ID = uuid.toString();                        System.out.println("【设备号测试】Constant.DEVICE_ID-->" + Constant.DEVICE_ID);                        // Write the value out to the prefs file                        prefs.edit().putString(PREFS_DEVICE_ID, uuid.toString() ).commit();                   }               }            }        }     }   }

更多相关文章

  1. android gps开发必备资料(含测试demo下载)
  2. android 判断是否连接钢琴和检测钢琴是哪个按键
  3. android判断当前设备的支持哪些Feature
  4. Android(安卓)cts测试命令
  5. 触摸按键Android的驱动解析
  6. Android中显示照片的Exif信息
  7. android ViewParent requestDisallowInterceptTouchEvent 测试
  8. Android串口设备的应用实现方案以及与WEB的交互
  9. android辅助开发工具包介绍

随机推荐

  1. Android(安卓)App请求获取Root权限
  2. android:autoLink
  3. Android中DIP与PX的转换
  4. RTC,system timer, android时间日期管理
  5. Android(安卓)P 版本中支持全面屏检测的a
  6. Android(安卓)UI - 带白边的自定义ImageV
  7. android 关于InputDispatcher出现Consume
  8. android下图片压缩
  9. android P虚拟按键点击位置加大的问题
  10. java.util.ConcurrentModificationExcept