How can I register my application on Android to ha

2019-03-03 15:56发布

The built-in barcode scanner application on Android (based, I think, on zxing) reads QR Codes and launches that data into an application based on the leading text. For example, "BEGIN:VCAL" might launch a calendar application; "http:" might launch a browser.

How can I "register" my application so the OS (or the Barcode application) will call it for a specific type (i.e. leading characters) of QR Code text?

2条回答
老娘就宠你
2楼-- · 2019-03-03 16:23

The comment above is mostly correct. However the app does not handle any actions internally. In the end it fires an Intent of some kind for all actions, such as adding a contact, opening a URL, adding a calendar event. By registering to handle those Intents, in the normal way (AndroidManifest.xml) you can register with Android to handle these actions.

If it's something very customized, maybe define a new URL scheme for it like "foobar:/...". Then register to handle such URIs in AndroidManifest.xml to get the same effect.

查看更多
Evening l夕情丶
3楼-- · 2019-03-03 16:35

How can I "register" my application so the OS (or the Barcode application) will call it for a specific type (i.e. leading characters) of QR Code text?

At least for ZXing's Barcode Scanner, you don't, near as I can tell. The roster of ResultHandler classes and their mappings to given prefixes is hardcoded in ResultHandlerFactory and ParsedResultType.

查看更多
登录 后发表回答