Reputation: 101
I want to create a progressive web application and at certain flow of that app i want a native android app
to be operational as there is some hardware access (USB devices) is required.
So i just want that the web app will redirect to the android native app
with some parameter. After the android app function is over the captured data will be sent back to web again with control of the application flow.
How to achieve this?
I am using a native SDK
so can't put that in web app.
If the user has not installed the native app before
, how it will be handled? it is mandatory to install the native app
in user's mobile?
Can it be like this the android app code will be ran through web app (without installing the native app in user's mobile)? Will it be awesome solution if possible?
Upvotes: 2
Views: 697
Reputation: 10100
Depending on what USB hardware you are trying to access and its support in WebUSB API- Targeted OS/browser, you might or might not be able to achieve directly in JS. You need to list down your exact hardware, what needs to be accessed via USB, Browser and OS, so someone can tell if you can achieve using WebAPI or not. Here is Chrome's documentation for WebAPI.
You can simply visit this site - what web can do today with HTML 5 APIs, under "Surroundings" section, if USB is green tick, that device-browser has support for USB. You might note that some browser/platform combination showing Green and some red cross(No Support).
If you conclude the USB hardware which you are trying to access is not supported by WebUSB API, only other way is to have an native code to be a layer between your PWA and hardware. Here is an example solution where PWA and native android app communicate via WebSockets. Communicating though web indents with params in URL is possible. But what you can do is limited. WebSockets might be a better option when what you need is more than a simple sting params. In the linked githug code, you can remove the barcode scanning logic and replace with USB functionality or any other hardware/native API access. Websockets solution + installing native app is good if you can make sure your user install the native app or prompt to install when one is not installed. This would be better option if you want to support web app running in your browser as well as installed ones(using add to home screen)
You can't put this native solution in web app unless you want to wrap it in Cordova kind of hybrid solution, where you might loose PWA service worker benefits in old devices with Webview version <40. This will be a good option if you want to ship your PWA app as a package via app stores and shipping two applications(native + web) is not possible/preferred.
Upvotes: 2