Open affan338 opened 2 years ago
We can fix it manually by adding the flag for PendingIntent in USBPrinterAdapter.java. Since android 31 and above required flag for Pending Intent.
Open the nodemodules/react-native-thermal-refceipt-printer-image-qr and check for the USBPrinterAdapter.java file under adapter folder.
Full File Path: _CURRENT_PROJECT_FOLDER_/node_modules/react-native-thermal-refceipt-printer-image-qr/android/src/java/com/pinmi/react/printer/adapter/USBPrinterAdapter.java
Search for PendingIntent.getBroadcast in USBPrinterAdapter.java
Replace the code from
this.mPermissionIndent = PendingIntent.getBroadcast(mContext, 0, new Intent(ACTION_USB_PERMISSION), 0);
with
this.mPermissionIndent = PendingIntent.getBroadcast(mContext, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
Run yarn android
now build will be success.
Note: Since we are doing it manually. Whenever you install / remove a npm dependency the USBPrinterAdapter.java will be updated. Do the above steps and run the app.
Hi! 👋
Firstly, thanks @palani-kamaraj ! 🙂
Today I used patch-package to patch react-native-thermal-receipt-printer-image-qr@0.1.10
for the project I'm working on.
Here is the diff that solved my problem based on #91 :
diff --git a/node_modules/react-native-thermal-receipt-printer-image-qr/android/src/main/java/com/pinmi/react/printer/adapter/USBPrinterAdapter.java b/node_modules/react-native-thermal-receipt-printer-image-qr/android/src/main/java/com/pinmi/react/printer/adapter/USBPrinterAdapter.java
index c4fc63a..f5089b2 100644
--- a/node_modules/react-native-thermal-receipt-printer-image-qr/android/src/main/java/com/pinmi/react/printer/adapter/USBPrinterAdapter.java
+++ b/node_modules/react-native-thermal-receipt-printer-image-qr/android/src/main/java/com/pinmi/react/printer/adapter/USBPrinterAdapter.java
@@ -107,7 +107,7 @@ public class USBPrinterAdapter implements PrinterAdapter {
public void init(ReactApplicationContext reactContext, Callback successCallback, Callback errorCallback) {
this.mContext = reactContext;
this.mUSBManager = (UsbManager) this.mContext.getSystemService(Context.USB_SERVICE);
- this.mPermissionIndent = PendingIntent.getBroadcast(mContext, 0, new Intent(ACTION_USB_PERMISSION), 0);
+ this.mPermissionIndent = PendingIntent.getBroadcast(mContext, 0, new Intent(ACTION_USB_PERMISSION), PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
filter.addAction(UsbManager.ACTION_USB_ACCESSORY_ATTACHED);
This issue body was partially generated by patch-package.
Thanks @vagnerlandio for suggesting patch-package. Yes it will help us to maintain our node_modules changes.
For Android above 11 init for USB printers is not working.
USBPrinter.init().then(() => { USBPrinter.getDeviceList().then(setPrinters, error => ToastAndroid.show(error, ToastAndroid.LONG)); });