设备ID写了公共方法,放在SP中
This commit is contained in:
@@ -77,6 +77,11 @@ public class MainActivity extends SDBaseActivity {
|
||||
// 应该是原来的保持屏幕常亮的代码
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
order_view.setWebViewClient(new WebViewClient());
|
||||
order_view.getSettings().setUseWideViewPort(true);
|
||||
order_view.getSettings().setLoadWithOverviewMode(true);
|
||||
order_view.getSettings().setBuiltInZoomControls(true);
|
||||
order_view.getSettings().setSupportZoom(true);
|
||||
order_view.setInitialScale(66);
|
||||
// current_date = TimeUtil.getCurrentDate();
|
||||
refreshWebView();
|
||||
// 启动Service
|
||||
@@ -184,7 +189,7 @@ public class MainActivity extends SDBaseActivity {
|
||||
|
||||
private void initQrIcon() {
|
||||
Integer venueId = SDAppConfig.getInstance().getVenueId();
|
||||
String deviceName = DeviceIdUtil.generateDeviceId(this);
|
||||
String deviceName = DeviceIdUtil.newGenerateDeviceName(this);
|
||||
String deviceType = SDAppConfig.getInstance().getDeviceType();
|
||||
String qrCert = deviceName + Constant.QRCODE_WORD + venueId + Constant.QRCODE_WORD + deviceType;
|
||||
if (venueId != null) {
|
||||
|
||||
@@ -87,7 +87,7 @@ public class ClientHandler extends SimpleChannelInboundHandler<String> {
|
||||
*/
|
||||
private HeartBeat getHbMessage() {
|
||||
HeartBeat hb = new HeartBeat();
|
||||
hb.setDeviceName(DeviceIdUtil.generateDeviceId(mContext));
|
||||
hb.setDeviceName(DeviceIdUtil.newGenerateDeviceName(mContext));
|
||||
hb.setVenueId(SDAppConfig.getInstance().getVenueId());
|
||||
hb.setDeviceType(SDAppConfig.getInstance().getDeviceType());
|
||||
return hb;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ydd.sportfaceid.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
@@ -22,6 +23,10 @@ import java.util.UUID;
|
||||
|
||||
public class DeviceIdUtil {
|
||||
static final private String INVALID_SERIAL_NUMBER = "12345678900";
|
||||
static final private String DEVICE_NAME = "DEVICE_NAME";
|
||||
|
||||
private static SharedPreferences sp;
|
||||
private static SharedPreferences.Editor spEditor;
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
static final public String generateDeviceId(Context context) {
|
||||
@@ -51,7 +56,6 @@ public class DeviceIdUtil {
|
||||
if (!TextUtils.isEmpty(deviceId) && !Build.UNKNOWN.equals(deviceId) && !INVALID_SERIAL_NUMBER.equals(deviceId)) {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
if (!"9774d56d682e549c".equals(deviceId) && !INVALID_SERIAL_NUMBER.equals(deviceId)
|
||||
&& !TextUtils.isEmpty(deviceId) && deviceId.length() > 6) {
|
||||
@@ -103,4 +107,24 @@ public class DeviceIdUtil {
|
||||
|
||||
return macSerial;
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容版本从SP中获取
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
static final public String newGenerateDeviceName(Context context) {
|
||||
String deviceName = "";
|
||||
if (sp == null) {
|
||||
sp = context.getSharedPreferences(DEVICE_NAME, Context.MODE_PRIVATE);
|
||||
spEditor = sp.edit();
|
||||
deviceName = UUID.randomUUID().toString().replace("-", "");
|
||||
spEditor.putString(DEVICE_NAME,deviceName);
|
||||
spEditor.commit();
|
||||
}else {
|
||||
deviceName = sp.getString(DEVICE_NAME,"ERROR_DEVICE_NAME");
|
||||
}
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user