Prechádzať zdrojové kódy

兼容安卓7.0以上版本

zh 9 mesiacov pred
rodič
commit
7a1ff0248a

+ 2 - 2
.idea/deploymentTargetSelector.xml

@@ -4,10 +4,10 @@
     <selectionStates>
       <SelectionState runConfigName="app">
         <option name="selectionMode" value="DROPDOWN" />
-        <DropdownSelection timestamp="2025-06-18T05:35:11.144657700Z">
+        <DropdownSelection timestamp="2025-06-25T05:14:23.925618200Z">
           <Target type="DEFAULT_BOOT">
             <handle>
-              <DeviceId pluginId="PhysicalDevice" identifier="serial=1a41f5baec1e896" />
+              <DeviceId pluginId="PhysicalDevice" identifier="serial=SCOPAIM7S2" />
             </handle>
           </Target>
         </DropdownSelection>

+ 1 - 1
app/build.gradle

@@ -8,7 +8,7 @@ android {
 
     defaultConfig {
         applicationId "com.baoshi.piece"
-        minSdk 28
+        minSdk 25
         targetSdk 34
         versionCode 1
         versionName "1.8"

+ 4 - 0
app/src/main/java/com/baoshi/piece/base/BaseWebViewActivity.java

@@ -24,6 +24,8 @@ import com.baoshi.piece.db.dao.DeliveryDao;
 import com.baoshi.piece.db.po.DeliveryRecord;
 import com.baoshi.piece.utils.JavaScriptInterface;
 import com.baoshi.piece.utils.MacAddressUtils;
+import com.baoshi.piece.utils.SoundManager;
+import com.baoshi.piece.utils.TipActionUtils;
 import com.baoshi.piece.utils.UpdateUtils;
 import com.yechaoa.yutils.LogUtil;
 import com.yechaoa.yutils.ToastUtil;
@@ -76,6 +78,7 @@ public abstract class BaseWebViewActivity extends BaseActivity<ActivityWebViewBi
         deleteOldRecordsOnStart();
         // 更新检查
         new UpdateUtils().init();
+        SoundManager.getInstance().init(this);
     }
 
 
@@ -99,6 +102,7 @@ public abstract class BaseWebViewActivity extends BaseActivity<ActivityWebViewBi
         viewBinding.webView.clearCache(true); // 清除缓存
         viewBinding.webView.clearHistory(); // 清除历史记录
         viewBinding.webView.clearFormData(); // 清除表单数据
+        SoundManager.getInstance().release(); // 释放音频播放器
     }
 
     @Override

+ 6 - 2
app/src/main/java/com/baoshi/piece/db/dao/DeliveryDao.java

@@ -14,6 +14,7 @@ import com.baoshi.piece.utils.TimeUtils;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 import java.util.TimeZone;
@@ -121,11 +122,14 @@ public class DeliveryDao {
         SQLiteDatabase db = dbHelper.getReadableDatabase();
         // 计算偏移量
         int offset = (pageIndex - 1) * pageSize;
+        // 获取当前日期(格式应与数据库中存储的日期格式一致)
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
+        String today = dateFormat.format(new Date());
         // 分页查询SQL
-        String sql = "SELECT * FROM delivery ORDER BY operationTime DESC LIMIT ? OFFSET ?";
+        String sql = "SELECT * FROM delivery WHERE date(operationTime) = ? ORDER BY operationTime DESC LIMIT ? OFFSET ?";
         Cursor cursor = null;
         try {
-            cursor = db.rawQuery(sql, new String[]{String.valueOf(pageSize), String.valueOf(offset)});
+            cursor = db.rawQuery(sql, new String[]{today, String.valueOf(pageSize), String.valueOf(offset)});
 
             if (cursor != null && cursor.moveToFirst()) {
                 do {

+ 5 - 5
app/src/main/java/com/baoshi/piece/utils/JavaScriptInterface.java

@@ -111,7 +111,7 @@ public class JavaScriptInterface {
      */
     @JavascriptInterface
     public void scanSuccessVib() {
-        TipActionUtils.getInstance().scanSuccessTip(activity);
+        SoundManager.getInstance().scanSuccessTip();
     }
 
     /**
@@ -119,7 +119,7 @@ public class JavaScriptInterface {
      */
     @JavascriptInterface
     public void scanErrorVib() {
-        TipActionUtils.getInstance().scanErrorTip(activity);
+        SoundManager.getInstance().error();
     }
 
     /**
@@ -127,7 +127,7 @@ public class JavaScriptInterface {
      */
     @JavascriptInterface
     public void scanError() {
-        TipActionUtils.getInstance().scanErr(activity);
+        SoundManager.getInstance().scanErrorTip();
     }
 
     /**
@@ -135,7 +135,7 @@ public class JavaScriptInterface {
      */
     @JavascriptInterface
     public void scanRepeatVib() {
-        TipActionUtils.getInstance().scanRepeatTip(activity);
+        SoundManager.getInstance().scanRepeatTip();
     }
 
     /**
@@ -143,7 +143,7 @@ public class JavaScriptInterface {
      */
     @JavascriptInterface
     public void reLoginTip() {
-        TipActionUtils.getInstance().reLoginTip(activity);
+        SoundManager.getInstance().reLoginTip();
     }
 
     @JavascriptInterface

+ 67 - 2
app/src/main/java/com/baoshi/piece/utils/MacAddressUtils.java

@@ -12,6 +12,7 @@ import android.os.Build;
 import android.util.Log;
 
 import com.baoshi.piece.BuildConfig;
+import com.yechaoa.yutils.GsonUtil;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -22,7 +23,11 @@ import java.io.InputStream;
 
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
 import java.nio.charset.StandardCharsets;
+import java.util.Enumeration;
 
 
 public class MacAddressUtils {
@@ -49,14 +54,74 @@ public class MacAddressUtils {
 
     // 读取MAC地址(精确匹配)
     public static String readMacAddress(Context context) {
-        // 1. 优先读取私有存储
+        // 1.
+        String mac = getMacAddressByIp();
+        if (mac != null) {
+            return mac.toLowerCase();
+        }
+
+        // 2. 备用方案读取MediaStore
+        mac = getMacFromInterface();
+        if (mac != null) {
+            return mac.toLowerCase();
+        }
+
+        // 3. 优先读取私有存储
         String result = readFromPrivateStorage(context);
         if (result != null) return result;
 
-        // 2. 备用方案读取MediaStore
+
+        // 4. 备用方案读取MediaStore
         return readFromMediaStore(context);
     }
 
+    public static String getMacFromInterface() {
+        try {
+            NetworkInterface nif = NetworkInterface.getByName("wlan0");
+            if (nif == null) return null;
+            byte[] macBytes = nif.getHardwareAddress();
+            if (macBytes == null) return null;
+            StringBuilder sb = new StringBuilder();
+            for (byte b : macBytes) {
+                sb.append(String.format("%02X:", b));
+            }
+            if (sb.length() > 0) sb.deleteCharAt(sb.length() - 1);
+            return sb.toString();
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    public static String getMacAddressByIp() {
+        try {
+            InetAddress ip = getLocalIpAddress(); // 获取设备本地 IP
+            NetworkInterface networkInterface = NetworkInterface.getByInetAddress(ip);
+            byte[] macBytes = networkInterface.getHardwareAddress();
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < macBytes.length; i++) {
+                sb.append(String.format("%02X%s", macBytes[i], (i < macBytes.length - 1) ? ":" : ""));
+            }
+            return sb.toString();
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    private static InetAddress getLocalIpAddress() throws SocketException {
+        Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
+        while (interfaces.hasMoreElements()) {
+            NetworkInterface nif = interfaces.nextElement();
+            Enumeration<InetAddress> addresses = nif.getInetAddresses();
+            while (addresses.hasMoreElements()) {
+                InetAddress address = addresses.nextElement();
+                if (!address.isLoopbackAddress() && address.getHostAddress().indexOf(':') == -1) {
+                    return address; // 返回首个非回环 IPv4 地址
+                }
+            }
+        }
+        return null;
+    }
+
     // 彻底删除所有相关文件(包含自动编号变体)
     private static void deleteAllMacAddressFiles(Context context) {
         // 1. 清理私有存储

+ 134 - 0
app/src/main/java/com/baoshi/piece/utils/SoundManager.java

@@ -0,0 +1,134 @@
+package com.baoshi.piece.utils;
+
+import android.app.Activity;
+import android.content.Context;
+import android.media.AudioAttributes;
+import android.media.AudioManager;
+import android.media.SoundPool;
+import android.os.Build;
+import android.os.VibrationEffect;
+import android.os.Vibrator;
+import android.util.Log;
+
+import com.baoshi.piece.R;
+
+public class SoundManager {
+    private static final String TAG = "SoundManager";
+    private volatile static SoundManager instance;
+    
+    // SoundPool 相关
+    private SoundPool soundPool;
+    private int errorSoundId;
+    private int scanErrorSoundId;
+    private int scanRepeatSoundId;
+    private int scanSuccessSoundId;
+    private int reLoginSoundId;
+    
+    // 振动相关
+    private Vibrator vibrator;
+    
+    // 单例模式
+    public static SoundManager getInstance() {
+        if (instance == null) {
+            synchronized (SoundManager.class) {
+                if (instance == null) {
+                    instance = new SoundManager();
+                }
+            }
+        }
+        return instance;
+    }
+    
+    // 初始化方法
+    public void init(Context context) {
+        release(); // 先释放之前的资源
+        
+        // 初始化SoundPool
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            AudioAttributes audioAttributes = new AudioAttributes.Builder()
+                    .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
+                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
+                    .build();
+            
+            soundPool = new SoundPool.Builder()
+                    .setMaxStreams(4) // 同时播放的最大音效数量
+                    .setAudioAttributes(audioAttributes)
+                    .build();
+        } else {
+            soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
+        }
+        
+        // 加载所有音效
+        errorSoundId = soundPool.load(context, R.raw.error, 1);
+        scanErrorSoundId = soundPool.load(context, R.raw.scanner_error, 1);
+        scanRepeatSoundId = soundPool.load(context, R.raw.scanner_repeat, 1);
+        scanSuccessSoundId = soundPool.load(context, R.raw.tip, 1);
+        reLoginSoundId = soundPool.load(context, R.raw.relogin, 1);
+        
+        // 初始化振动器
+        vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
+        
+        // 设置加载完成监听器
+        soundPool.setOnLoadCompleteListener((soundPool, sampleId, status) -> {
+            if (status == 0) {
+                Log.d(TAG, "音效加载完成, ID: " + sampleId);
+            } else {
+                Log.e(TAG, "音效加载失败, ID: " + sampleId);
+            }
+        });
+    }
+    
+    // 释放资源
+    public void release() {
+        if (soundPool != null) {
+            soundPool.release();
+            soundPool = null;
+        }
+        vibrator = null;
+    }
+
+    // 错误提示
+    public void error() {
+        playSound(errorSoundId);
+    }
+
+    // 扫描错误提示
+    public void scanErrorTip() {
+        playSound(scanErrorSoundId);
+    }
+    
+    // 重新登录提示
+    public void reLoginTip() {
+        playSound(reLoginSoundId);
+    }
+    
+    // 扫描重复提示(带振动)
+    public void scanRepeatTip() {
+        playSound(scanRepeatSoundId);
+        vibrate(1000);
+    }
+    
+    // 扫描成功提示
+    public void scanSuccessTip() {
+        playSound(scanSuccessSoundId);
+    }
+
+    
+    // 私有方法:播放音效
+    private void playSound(int soundId) {
+        if (soundPool != null && soundId != 0) {
+            soundPool.play(soundId, 1.0f, 1.0f, 1, 0, 1.0f);
+        }
+    }
+    
+    // 私有方法:振动
+    private void vibrate(long milliseconds) {
+        if (vibrator != null && vibrator.hasVibrator()) {
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+                vibrator.vibrate(VibrationEffect.createOneShot(milliseconds, VibrationEffect.DEFAULT_AMPLITUDE));
+            } else {
+                vibrator.vibrate(milliseconds);
+            }
+        }
+    }
+}

+ 0 - 6
app/src/main/res/mipmap-anydpi/ic_launcher.xml

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
-    <background android:drawable="@drawable/ic_launcher_background" />
-    <foreground android:drawable="@drawable/ic_launcher_foreground" />
-    <monochrome android:drawable="@drawable/ic_launcher_foreground" />
-</adaptive-icon>

+ 0 - 6
app/src/main/res/mipmap-anydpi/ic_launcher_round.xml

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
-    <background android:drawable="@drawable/ic_launcher_background" />
-    <foreground android:drawable="@drawable/ic_launcher_foreground" />
-    <monochrome android:drawable="@drawable/ic_launcher_foreground" />
-</adaptive-icon>

+ 1 - 1
config/piece.cnf

@@ -1,6 +1,6 @@
 {
 	"version" 	: "1.8",
 	"url"	: "https://swms.baoshi56.com/statics/storage/app/PIECE.1.8.apk",
-	"title"	: "1. 页面优化",
+	"title"	: "1. 兼容安卓 7.1 及以上版本",
 	"content"	: "宝时计件"
 }