0

I'm developing a Nativescript application that will be run on an Android device connected to a bluetooth barcode scanner. This app will run on a supermarket where it will display a product price. This barcode scanner acts like a external keyboard that will type quickly the barcode number and send this number to the device. How to trigger keyUp event on entire Page (Nativescript component) without using TextEdit alike components?

Felipe Campos
  • 184
  • 1
  • 3
  • Does this barcode scanner have any SDK for integration? how it could know where to send the numbers, the device but which activity would receive it? It uses an intent? – Manoj Jan 26 '19 at 18:36
  • @Manoj this barcode scanner acts like a keyboard input. When some barcode is scanned, it will send all the numbers rapidly (mimicking a fast keyboard typing) and it will read those numbers and send the request to the server. No need for SDK since the operation of the barcode scanner is that simple. – Felipe Campos Jan 28 '19 at 14:22
  • Then I think just the `textChange` event should work here. Did you try that? – Manoj Jan 28 '19 at 14:29
  • Manoj unfortunately I'm not using any TextEdit components. I want the HostComponent to be listening for keystrokes. If I use @HostListener in pure Angular for web, it works just fine, but for some reason, probably because of the Nativescript Page (and not Document) architecture this simply doesn't works. If everything goes wrong, I will try to use an "invisible" EditText component avoiding showing the virtual keyboard or try a native Android solution instead. – Felipe Campos Jan 28 '19 at 14:44
  • 1
    Oh, I get it. `@HostListener` can't work her as Activity doesn't listen to keypress by default. You will have to [extend the default activity](https://docs.nativescript.org/core-concepts/android-runtime/advanced-topics/extend-application-activity) and override the `onKeyDown` method to get inputs. – Manoj Jan 28 '19 at 14:46
  • @Manoj thanks for your feedback, but I had stumbled upon this link before. The problem is that my nativescript transpiler doesn't recognize the android namespace. I've tried using the js file also, but with no success, it seems that the key events are not implemented on the nativescript activity wrapper. Anyway, I've decided to go to the Android Studio native way. But thanks for your help and time. – Felipe Campos Jan 31 '19 at 00:50
  • Yes, you are right it's not. But the whole purpose of JavaProxy is to let you extend your own activity without depending on NativeScript. You can override the [keyup method](https://developer.android.com/reference/android/app/Activity.html#onKeyUp(int,%20android.view.KeyEvent)) yourself and get full control. – Manoj Jan 31 '19 at 20:05
  • @Manoj thanks for your help! In fact, I can override the behaviour of keyup method extending the activity via the JavaProxy. The problem that I was getting was about the ".android" namespace definitions that were not declared and i could not compile the solution. The problem was solved by installing the tns-platform-declarations as a development dependency (https://stackoverflow.com/questions/37523071/how-can-i-access-native-api-in-nativescript-when-i-use-typescript) and now everything is working like a charm! – Felipe Campos Feb 05 '19 at 14:16
  • Felipe, how did you do it ? I also need to implement the same – Nick Chan Abdullah Sep 30 '19 at 05:57

0 Answers0