react-native-star-io10 icon indicating copy to clipboard operation
react-native-star-io10 copied to clipboard

Unable to search for devices and printers on latest android version.

Open hamzaahzam opened this issue 3 years ago • 7 comments

Description

Unable to search for devices and printers on latest android version.

Device where the bug occurs

  • Device: Samsung Galaxy A12, Redmi note 10 Pro
  • OS: Android 11,Android 12
  • Build by Android Studio chipmunk
  • Version of react-native: { "react": "17.0.2", "react-native": "0.68.2", "react-native-star-io10": "^1.2.0", }

Your printer

  • Model Names: Portable Thermal Printer SM-L300
  • Firmware Version: SM-L300
  • Interface: Bluetooth

Your development environment

macOS

Also, the result of executing the command npx react-native info.

Code To Reproduce

const discoverPrinters = async () => {
    try {
      var printersToSave = [];
      var printerList = [];
      var interfaceTypes = [
        Platform.OS === 'ios'
          ? InterfaceType.BluetoothLE
          : InterfaceType.Bluetooth,
      ];
      var manager = await StarDeviceDiscoveryManagerFactory.create(
        interfaceTypes,
      );

      manager.discoveryTime = 5000;

      // Callback for printer found.
      manager.onPrinterFound = printer => {
        printersToSave.push(printer);
        printerList.push({
          label: printer.connectionSettings.identifier,
          value: printer,
        });
        if (printer.connectionSettings.identifier === printerId) {
          // setSelectedPrinter(printer)
          setSelectedPrinter({
            label: printer.connectionSettings.identifier,
            value: printer,
          });
          dispatch(updatePrinter(printer));
        }
        // if()
      };

      manager.onDiscoveryFinished = () => {
        setPrinters(printerList);
      };
      await manager.startDiscovery();
    } catch (error) {}
  };

Error

In android 12 while running the above code app crashes and in android 11 app doesn't crashes but unable to scan nearby printer. But same code works fine on android 10 and earlier versions.

hamzaahzam avatar Jun 06 '22 11:06 hamzaahzam

@hamzaahzam Could you please refer to the following URL and check if the permissions are properly granted according to the target SDK version? https://github.com/star-micronics/react-native-star-io10#android

bandit-ibayashi avatar Jun 08 '22 00:06 bandit-ibayashi

@bandit-ibayashi I have added all the permissions for android it is crashing on my Redmi Note 10 Pro android version 12

DevHumzaAhzam avatar Jun 08 '22 07:06 DevHumzaAhzam

In Logs I am getting this error java.lang.SecurityException: Need android.permission.BLUETOOTH_CONNECT permission for android.content.AttributionSource@655f4942: AdapterService getBondedDevices

DevHumzaAhzam avatar Jun 08 '22 09:06 DevHumzaAhzam

same issue i am facing

mohsinmughal1630 avatar Jun 08 '22 13:06 mohsinmughal1630

@hamzaahzam

It is possible to request the permission android.permission.BLUETOOTH_CONNECT with the following code, but could you still not get the permission by doing this? https://github.com/star-micronics/react-native-star-io10/blob/e544aacab74b480540558641dc8003a7126f30d8/example/samples/discovery/App.tsx#L101

This code must be executed when Android 12 or later and targetSDKVersion is 31 or later.

https://github.com/star-micronics/react-native-star-io10/blob/e544aacab74b480540558641dc8003a7126f30d8/example/samples/discovery/App.tsx#L38

I executed our discovery sample code on a Google Pixel 6 with Android 12 and was able to successfully search for Bluetooth printers.

bandit-ibayashi avatar Jun 13 '22 03:06 bandit-ibayashi

@bandit-ibayashi Thanks after requesting android permission I was able to find printers and send request for printing.

But I am facing an issue on Redmi Note 10 Pro after requesting permission it starts searching for printers but always returns nothing on onDiscoveryFinished

DevHumzaAhzam avatar Jun 16 '22 12:06 DevHumzaAhzam

@DevHumzaAhzam

Found printers are retrieved with onPrinterFound property, not onDiscoveryFinished. onDiscoveryFinished property indicates that it only notifies the user that the Discovery process is finished and does not return information on the printers found as a result of the Discovery process. You can also refer the sample code here.

Or would it be a case where onDiscoveryFinished is issued as soon as startDiscovery method is executed in your situation with Redmi Note 10 Pro?

bandit-ibayashi avatar Jun 20 '22 04:06 bandit-ibayashi

We will close it once there have been no comments for a certain period of time. If you continue to experience this problem, please create a new Issue.

bandit-ibayashi avatar Sep 28 '22 07:09 bandit-ibayashi