|
1 | 1 | package com.sunmi.peripheral.printer; |
2 | 2 |
|
| 3 | +import android.annotation.SuppressLint; |
3 | 4 | import android.content.Context; |
4 | 5 | import android.content.Intent; |
5 | 6 | import android.content.IntentFilter; |
6 | 7 | import android.os.Build; |
7 | | -import android.os.SystemProperties; |
8 | 8 | import android.text.TextUtils; |
9 | 9 | import android.util.Log; |
10 | 10 |
|
11 | | -import java.io.BufferedReader; |
12 | | -import java.io.FileReader; |
13 | 11 | import java.lang.reflect.Method; |
14 | 12 | import java.util.ArrayList; |
15 | 13 |
|
@@ -188,28 +186,38 @@ private static String filterModel(String str) { |
188 | 186 | return ""; |
189 | 187 | } |
190 | 188 |
|
191 | | - public static boolean isSPIPrint() { |
192 | | - if (TextUtils.equals("M2-202", Build.MODEL)) { |
193 | | - return SystemProperties.getBoolean("persist.sys.isSPI", false); |
194 | | - } else if (TextUtils.equals("M2-Pro", Build.MODEL)) { |
195 | | - return true; |
196 | | - } |
197 | | - BufferedReader reader; |
| 189 | + public static String getSystemProperty(String key) { |
198 | 190 | try { |
199 | | - reader = new BufferedReader(new FileReader("/proc/neostra_hw_info")); |
200 | | - String line; |
201 | | - while ((line = reader.readLine()) != null) { |
202 | | - Log.d("printlibrary", "hasSPI" + line.contains("SPI=ON")); |
203 | | - return line.contains("SPI=ON") ? true : false; |
204 | | - } |
205 | | - reader.close(); |
206 | | - } catch (Exception e) { |
207 | | - // TODO Auto-generated catch block\r |
208 | | - e.printStackTrace(); |
209 | | - } |
210 | | - return false; |
| 191 | + @SuppressLint("PrivateApi") |
| 192 | + Class<?> clz = Class.forName("android.os.SystemProperties"); |
| 193 | + Method getMethod = clz.getMethod("get", String.class, String.class); |
| 194 | + return (String) getMethod.invoke(clz, key, ""); |
| 195 | + } catch (Exception e) {/**/} |
| 196 | + return ""; |
211 | 197 | } |
212 | 198 |
|
| 199 | +// public static boolean isSPIPrint() { |
| 200 | +// if (TextUtils.equals("M2-202", Build.MODEL)) { |
| 201 | +// return SystemProperties.getBoolean("persist.sys.isSPI", false); |
| 202 | +// } else if (TextUtils.equals("M2-Pro", Build.MODEL)) { |
| 203 | +// return true; |
| 204 | +// } |
| 205 | +// BufferedReader reader; |
| 206 | +// try { |
| 207 | +// reader = new BufferedReader(new FileReader("/proc/neostra_hw_info")); |
| 208 | +// String line; |
| 209 | +// while ((line = reader.readLine()) != null) { |
| 210 | +// Log.d("printlibrary", "hasSPI" + line.contains("SPI=ON")); |
| 211 | +// return line.contains("SPI=ON") ? true : false; |
| 212 | +// } |
| 213 | +// reader.close(); |
| 214 | +// } catch (Exception e) { |
| 215 | +// // TODO Auto-generated catch block\r |
| 216 | +// e.printStackTrace(); |
| 217 | +// } |
| 218 | +// return false; |
| 219 | +// } |
| 220 | + |
213 | 221 | //获取电量 |
214 | 222 | public static int getElect(Context context) { |
215 | 223 | IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); |
|
0 commit comments