Fetching a scan from ZXing on Android (Kivy)
August 10, 2014 1 Comment
Did a bit of mucking around to fetch a scan from ZXing using an intent. Turned out to be more trouble than it was worth unfortunately because ZXing takes a long time to recognise a barcode. Intent code is:
Intent = autoclass('android.content.Intent') intent = Intent() intent.setAction("com.google.zxing.client.android.SCAN") Logger.debug("build: about to start activity for result") PythonActivity.mActivity.startActivityForResult(intent, 0x123)
It goes without saying that you need to have ZXing already installed on the device. Apparently it will also work with other scanners, but I haven’t tried.
You also need to have a callback to handle the returned result:
def on_activity_result(self, requestCode, resultCode, data): isbn = data.getStringExtra("SCAN_RESULT") # do other stuff...
And this callback must first be bound:
activity.bind(on_new_intent=self.on_new_intent,on_activity_result=self.on_activity_result) # earlier: from android import activity