From 7c8ce9b9a7d3fc1aaa4a621e86415b25ad10a34f Mon Sep 17 00:00:00 2001
From: panlili2024 <14743743+panlili2024@user.noreply.gitee.com>
Date: 星期三, 19 三月 2025 09:36:28 +0800
Subject: [PATCH] 添加source屏扫码流程
---
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/common/utils/SPUtils.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/common/utils/SPUtils.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/common/utils/SPUtils.java
index 17ceeab..60f6c5f 100644
--- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/common/utils/SPUtils.java
+++ b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/common/utils/SPUtils.java
@@ -2,11 +2,17 @@
import android.content.Context;
import android.content.SharedPreferences;
+import android.util.Base64;
import com.hdl.sdk.common.HDLSdk;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
@@ -146,5 +152,52 @@
.apply();
}
+ private static String Object2String(Object object) {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ ObjectOutputStream objectOutputStream = null;
+ try {
+ objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
+ objectOutputStream.writeObject(object);
+ String string = new String(Base64.encode(byteArrayOutputStream.toByteArray(), Base64.DEFAULT));
+ objectOutputStream.close();
+ return string;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ private static Object String2Object(String objectString) {
+ byte[] mobileBytes = Base64.decode(objectString.getBytes(), Base64.DEFAULT);
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(mobileBytes);
+ ObjectInputStream objectInputStream = null;
+ try {
+ objectInputStream = new ObjectInputStream(byteArrayInputStream);
+ Object object = objectInputStream.readObject();
+ objectInputStream.close();
+ return object;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public static void saveSerializableEntity(String key, Object saveObject) {
+ SharedPreferences.Editor editor = getAppPreference().edit();
+ String string = Object2String(saveObject);
+ editor.putString(key, string);
+ editor.commit();
+ }
+
+ public static Object getSerializableEntity(String key) {
+ String string = getAppPreference().getString(key, null);
+ if (string != null) {
+ Object object = String2Object(string);
+ return object;
+ } else {
+ return null;
+ }
+ }
+
}
--
Gitblit v1.8.0