From 73aff29ec7ec7dce8b74ec012429f9be408dac70 Mon Sep 17 00:00:00 2001 From: the-deadshot Date: Tue, 7 Mar 2023 22:12:49 +0530 Subject: [PATCH] :hammer: make plugin support for SDK greater than 30 --- plugin.xml | 9 +++++++-- src/android/BluetoothPrinter.java | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/plugin.xml b/plugin.xml index 26729ac..d45d5e4 100644 --- a/plugin.xml +++ b/plugin.xml @@ -29,12 +29,17 @@ + + - + + + - + \ No newline at end of file diff --git a/src/android/BluetoothPrinter.java b/src/android/BluetoothPrinter.java index 3bedde2..dfaf555 100644 --- a/src/android/BluetoothPrinter.java +++ b/src/android/BluetoothPrinter.java @@ -36,6 +36,9 @@ import java.util.ArrayList; import java.util.List; +import androidx.core.app.ActivityCompat; +import androidx.core.content.PermissionChecker; + public class BluetoothPrinter extends CordovaPlugin { private static final String LOG_TAG = "BluetoothPrinter"; @@ -86,9 +89,18 @@ public class BluetoothPrinter extends CordovaPlugin { public static final byte[] BARCODE_ITF = { 0x1D, 0x6B, 0x05 }; public static final byte[] BARCODE_CODABAR = { 0x1D, 0x6B, 0x06 }; + public static final int REQUEST_BLUETOOTH_PERMISSION = 1; + @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("status")) { + if (PermissionChecker.checkSelfPermission(this.cordova.getContext(), android.Manifest.permission.BLUETOOTH_SCAN) != PermissionChecker.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions( + this.cordova.getActivity(), + new String[] { android.Manifest.permission.BLUETOOTH_SCAN, android.Manifest.permission.BLUETOOTH_CONNECT }, + REQUEST_BLUETOOTH_PERMISSION + ); + } checkBTStatus(callbackContext); return true; } else if (action.equals("list")) { @@ -108,7 +120,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo } return true; } else if (action.equals("connected")) { - connected(callbackContext); + connected(callbackContext); return true; } else if (action.equals("disconnect")) { try { @@ -1102,4 +1114,4 @@ public static byte[] sysCopy(List srcArrays) { } return destArray; } -} +} \ No newline at end of file