Skip to content

Commit

Permalink
Merge pull request #69 from the-deadshot/make-plugin-support-for-sdk-…
Browse files Browse the repository at this point in the history
…greater-than-30

🔨 make plugin support for SDK greater than 30
  • Loading branch information
CesarBalzer committed May 15, 2023
2 parents 8efc83d + 73aff29 commit 6420fcb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 7 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@
<param name="android-package" value="br.com.cordova.printer.bluetooth.BluetoothPrinter"/>
</feature>
</config-file>

<framework src="androidx.appcompat:appcompat:1.6.1" />

<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
</config-file>

<source-file src="src/android/BluetoothPrinter.java" target-dir="src/br/com/cordova/printer/bluetooth" />

</platform>
</plugin>
</plugin>
16 changes: 14 additions & 2 deletions src/android/BluetoothPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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")) {
Expand All @@ -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 {
Expand Down Expand Up @@ -1102,4 +1114,4 @@ public static byte[] sysCopy(List<byte[]> srcArrays) {
}
return destArray;
}
}
}

1 comment on commit 6420fcb

@LimSieKuang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have edited the code but this plugin can't work on api 33

Please sign in to comment.