Surile / react-native-sunmi-printer

商米内置打印机
MIT License
47 stars 33 forks source link

Detect if its a Sunmi device #41

Closed aajahid closed 11 months ago

aajahid commented 11 months ago

We are working on an app that will run on generic android devices and also on Sunmi devices. Our expectation -

  1. When its sunmi device - it will run the print action
  2. When its generic android device - it won't do anything.

On Sunmi device - its working fine. But on non Sunmi device its crashing. I either need a way to detect if the app is running on a Sunmi device or support for try catch

On non Sunmi devices - it doesn't have the SDK's and it throws android native null object reference. Putting the print function with try catch can't catch the native library exception.

Any idea how would I be able to

  1. Detect if the SDK available
  2. If its an Sunmi device or not
  3. Try/catch support

image

Surile commented 11 months ago

This interface is only suitable for determining Sunmi devices. You need to use getBrand in react-native-device-info to determine whether it is a Sunmi device.

aajahid commented 11 months ago

Actually found the hasPrinter works on other devices without crashing. So before any print event - I just need to check hasPrinter

This actually solve my issue - on non Sunmi device - its always false.

Thank you @Surile for the library, really helpful.