@nitra/zebra 6.1.7 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
13
13
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
14
14
|
|
|
15
|
+
<!-- Wi-Fi info (SSID) on Android 13+ -->
|
|
16
|
+
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" />
|
|
17
|
+
|
|
15
18
|
<!-- Feature declarations -->
|
|
16
19
|
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
|
|
17
20
|
<uses-feature android:name="android.hardware.bluetooth" android:required="true" />
|
|
@@ -44,6 +44,11 @@ import java.util.concurrent.Executors;
|
|
|
44
44
|
import java.util.concurrent.Future;
|
|
45
45
|
import java.util.concurrent.TimeUnit;
|
|
46
46
|
import java.util.concurrent.TimeoutException;
|
|
47
|
+
import android.net.ConnectivityManager;
|
|
48
|
+
import android.net.Network;
|
|
49
|
+
import android.net.NetworkCapabilities;
|
|
50
|
+
import android.net.wifi.WifiInfo;
|
|
51
|
+
import android.net.wifi.WifiManager;
|
|
47
52
|
|
|
48
53
|
@CapacitorPlugin(name = "ZebraPrinter", permissions = {
|
|
49
54
|
@Permission(alias = "bluetooth", strings = {
|
|
@@ -52,7 +57,8 @@ import java.util.concurrent.TimeoutException;
|
|
|
52
57
|
Manifest.permission.BLUETOOTH_CONNECT,
|
|
53
58
|
Manifest.permission.BLUETOOTH_SCAN,
|
|
54
59
|
Manifest.permission.ACCESS_FINE_LOCATION,
|
|
55
|
-
Manifest.permission.ACCESS_COARSE_LOCATION
|
|
60
|
+
Manifest.permission.ACCESS_COARSE_LOCATION,
|
|
61
|
+
Manifest.permission.NEARBY_WIFI_DEVICES
|
|
56
62
|
})
|
|
57
63
|
})
|
|
58
64
|
public class ZebraPrinter extends Plugin {
|
|
@@ -176,6 +182,7 @@ public class ZebraPrinter extends Plugin {
|
|
|
176
182
|
permissionsToRequest.add(Manifest.permission.BLUETOOTH_ADMIN);
|
|
177
183
|
permissionsToRequest.add(Manifest.permission.ACCESS_FINE_LOCATION);
|
|
178
184
|
permissionsToRequest.add(Manifest.permission.ACCESS_COARSE_LOCATION);
|
|
185
|
+
permissionsToRequest.add(Manifest.permission.NEARBY_WIFI_DEVICES);
|
|
179
186
|
|
|
180
187
|
// Add Android 12+ Bluetooth permissions
|
|
181
188
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
@@ -1342,4 +1349,70 @@ public class ZebraPrinter extends Plugin {
|
|
|
1342
1349
|
result.put("connected", false);
|
|
1343
1350
|
call.resolve(result);
|
|
1344
1351
|
}
|
|
1352
|
+
|
|
1353
|
+
@PluginMethod
|
|
1354
|
+
public void getNetworkInfo(PluginCall call) {
|
|
1355
|
+
JSObject result = new JSObject();
|
|
1356
|
+
result.put("supported", true);
|
|
1357
|
+
|
|
1358
|
+
String type = "unknown";
|
|
1359
|
+
String ip = null;
|
|
1360
|
+
String ssid = null;
|
|
1361
|
+
|
|
1362
|
+
try {
|
|
1363
|
+
WifiManager wifiManager = (WifiManager) getContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
|
1364
|
+
ConnectivityManager connectivityManager = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
1365
|
+
|
|
1366
|
+
if (wifiManager != null) {
|
|
1367
|
+
WifiInfo info = wifiManager.getConnectionInfo();
|
|
1368
|
+
if (info != null && info.getNetworkId() != -1) {
|
|
1369
|
+
int ipInt = info.getIpAddress();
|
|
1370
|
+
if (ipInt != 0) {
|
|
1371
|
+
ip = intToIp(ipInt);
|
|
1372
|
+
}
|
|
1373
|
+
ssid = info.getSSID();
|
|
1374
|
+
if (ssid != null) {
|
|
1375
|
+
ssid = ssid.replace("\"", "");
|
|
1376
|
+
if ("<unknown ssid>".equalsIgnoreCase(ssid)) {
|
|
1377
|
+
ssid = null;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
type = "wifi";
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
if ("unknown".equals(type) && connectivityManager != null) {
|
|
1385
|
+
Network activeNetwork = connectivityManager.getActiveNetwork();
|
|
1386
|
+
if (activeNetwork != null) {
|
|
1387
|
+
NetworkCapabilities caps = connectivityManager.getNetworkCapabilities(activeNetwork);
|
|
1388
|
+
if (caps != null && caps.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
|
1389
|
+
type = "cell";
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
} catch (Exception e) {
|
|
1394
|
+
Log.w(TAG, "⚠️ getNetworkInfo failed: " + e.getMessage());
|
|
1395
|
+
result.put("error", e.getMessage());
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
result.put("type", type);
|
|
1399
|
+
if (ip != null) {
|
|
1400
|
+
result.put("ip", ip);
|
|
1401
|
+
}
|
|
1402
|
+
if (ssid != null) {
|
|
1403
|
+
result.put("ssid", ssid);
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
call.resolve(result);
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
private String intToIp(int ip) {
|
|
1410
|
+
return String.format(
|
|
1411
|
+
"%d.%d.%d.%d",
|
|
1412
|
+
(ip & 0xff),
|
|
1413
|
+
(ip >> 8 & 0xff),
|
|
1414
|
+
(ip >> 16 & 0xff),
|
|
1415
|
+
(ip >> 24 & 0xff)
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1345
1418
|
}
|