添加第一次启动注册设备
This commit is contained in:
@ -4,10 +4,10 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Environment;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.os.Environment;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
@ -77,16 +77,6 @@ public class TokenUtils {
|
||||
AppController.addToRequestQueue(request, TokenUtils.class);
|
||||
}
|
||||
|
||||
// 保存用户设备id
|
||||
public static synchronized void saveDeviceId(Context context, String device_id) {
|
||||
|
||||
}
|
||||
|
||||
// 获取用户设备id
|
||||
public static synchronized String getDeviceId(Context context) {
|
||||
return "57ddf9348a3200304f441112";
|
||||
}
|
||||
|
||||
// 获取用户token
|
||||
public static synchronized String getToken(Context context) {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE,
|
||||
@ -151,35 +141,34 @@ public class TokenUtils {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void saveDeviceID(String deviceID, Context context){
|
||||
saveSharedPreferences(deviceID, context);
|
||||
saveDataFile(deviceID, context);
|
||||
svaeSDCard(deviceID, "/gh-uuid");//SDCard根目录
|
||||
svaeSDCard(deviceID, "/system");//SDCard system目录
|
||||
svaeSDCard(deviceID, "/data");//SDCard data目录
|
||||
public static synchronized void saveDeviceId(Context context, String device_id){
|
||||
saveSharedPreferences(context, device_id);
|
||||
saveDataFile(context, device_id);
|
||||
svaeSDCard(device_id, "/gh-uuid");//SDCard根目录
|
||||
svaeSDCard(device_id, "/system");//SDCard system目录
|
||||
svaeSDCard(device_id, "/data");//SDCard data目录
|
||||
}
|
||||
|
||||
//将uuid存到sp
|
||||
private static void saveSharedPreferences(String deviceID, Context context) {
|
||||
private static void saveSharedPreferences(Context context, String device_id) {
|
||||
SharedPreferences sp = context.getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor edit = sp.edit();
|
||||
edit.putString("uuid", deviceID);
|
||||
edit.putString("uuid", device_id);
|
||||
edit.apply();
|
||||
Utils.log("saveDeviceID", "保存成功SP");
|
||||
Utils.log("saveDeviceId", "保存成功SP");
|
||||
}
|
||||
|
||||
//将uuid存到data/data/PackageName/files文件夹下
|
||||
private static void saveDataFile(String deviceID, Context context) {
|
||||
private static void saveDataFile(Context context, String device_id) {
|
||||
FileOutputStream fops;
|
||||
try {
|
||||
fops = context.openFileOutput("uuid", Context.MODE_PRIVATE);
|
||||
fops.write(deviceID.getBytes());
|
||||
fops.write(device_id.getBytes());
|
||||
fops.close();
|
||||
Utils.log("saveDeviceID", "保存成功DataFile");
|
||||
Utils.log("saveDeviceId", "保存成功DataFile");
|
||||
} catch (Exception e) {
|
||||
Utils.log("保存uuid到data/data/PackageName/files文件异常" + e.toString());
|
||||
e.printStackTrace();
|
||||
@ -187,7 +176,7 @@ public class TokenUtils {
|
||||
}
|
||||
|
||||
//将uuid存到SD卡
|
||||
private static void svaeSDCard(String deviceID,String saveDir) {
|
||||
private static void svaeSDCard(String device_id, String saveDir) {
|
||||
File sdCardDir = Environment.getExternalStorageDirectory();
|
||||
String path = sdCardDir.getPath() + saveDir;
|
||||
|
||||
@ -207,9 +196,9 @@ public class TokenUtils {
|
||||
FileOutputStream fos;
|
||||
try {
|
||||
fos = new FileOutputStream(writeFile);
|
||||
fos.write(deviceID.getBytes());
|
||||
fos.write(device_id.getBytes());
|
||||
fos.close();
|
||||
Utils.log("saveDeviceID", "保存成功SDCard"+"目录为:"+saveDir);
|
||||
Utils.log("saveDeviceId", "保存成功SDCard"+"目录为:"+saveDir);
|
||||
} catch (Exception e) {
|
||||
Utils.log("保存uuid到SDCard异常" + saveDir + e.toString());
|
||||
e.printStackTrace();
|
||||
@ -226,10 +215,10 @@ public class TokenUtils {
|
||||
}
|
||||
// 检查
|
||||
if (loadSharedPreferences(context, true) == null){
|
||||
saveSharedPreferences(uuid, context);
|
||||
saveSharedPreferences(context, uuid);
|
||||
}
|
||||
if (loadDataFile(context ,true) == null){
|
||||
saveDataFile(uuid, context);
|
||||
saveDataFile(context, uuid);
|
||||
}
|
||||
String[] dirName = {"/gh-uuid", "/system", "/data"};
|
||||
for (int i = 0; i< 3; i++) {
|
||||
@ -240,7 +229,7 @@ public class TokenUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDeviceID(Context context) {
|
||||
public static synchronized String getDeviceId(Context context) {
|
||||
return loadSharedPreferences(context, false);
|
||||
}
|
||||
|
||||
@ -254,7 +243,7 @@ public class TokenUtils {
|
||||
if (uuid == null){
|
||||
return loadDataFile(context, false);
|
||||
}
|
||||
Utils.log("getDeviceID", "获取成功SP" + uuid);
|
||||
Utils.log("getDeviceId", "获取成功SP" + uuid);
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@ -270,7 +259,7 @@ public class TokenUtils {
|
||||
while ((count = fis.read(b)) != -1) {
|
||||
uuid = new String(b, 0, count, "UTF-8");
|
||||
}
|
||||
Utils.log("getDeviceID", "获取成功DataFile"+ uuid);
|
||||
Utils.log("getDeviceId", "获取成功DataFile"+ uuid);
|
||||
return uuid;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -305,7 +294,7 @@ public class TokenUtils {
|
||||
}
|
||||
bos.close();
|
||||
fis.close();
|
||||
Utils.log("getDeviceID", "获取成功SDCard"+"目录为:"+saveDir+"::"+bos.toString());
|
||||
Utils.log("getDeviceId", "获取成功SDCard"+"目录为:"+saveDir+"::"+bos.toString());
|
||||
return bos.toString();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user