We have developed a PWA Progressive Web App in React and we need to run background service to fetch the location of user at all the time as PWA app cannot do that so we created a native wrapper to handle this
The Native Android Wrapper is a WebView which load the PWA app url
Everything works fine till here , Now we need to do communication from Android to PWA React App
we have tried adding webView.addJavascriptInterface and the guide lines mentioned in
https://developer.android.com/reference/android/webkit/WebView
but nothing works
can any one help with suggestions or links to communicate between Native Wrapper and a PWA app
Thanks
We have tried the Guideline of Android created Bridge between Android and React PWA app but did not work
https://developer.android.com/reference/android/webkit/WebView
2
Answers
If you want send data to Webview :
make a function in your React inside window like:
now in your native android code like React-Native :
capture geo locations and send it into PWA like this:
There are a lot of configurations and versions that you can be using, so it is too hard give the right solution.
Here some approaches that could help you:
Access to Javascript Storage
If you save some key-value in the Javascript storage like the oauth2 token, according to these links you should be able to access from WebView
Access to the url value
If we are talking of access_token which expires, you should know that this is not a "secret" to the user. I mean this value usually should be accessed for any javascript part inside of the web page. Similar for native applications. As examples:
If you understood that to have the access_token in the url in a trusted device with trusted user, is not a security concern, you could append the token to your url and then using native android the the full url with these: