I have a website which is responsive and push notification feature enabled. In my native android app, if i load my website in a WebView
, then the pop up which usually comes in chrome/firefox to ask if user wants to allow push notification or not, doesn't shows up in WebView
. And obviously the WebView
won't support the same web push notification for the app. I know how to implement GCM or FCM in app to enable mobile push, but i wanted to know if it possible just to club the web push notification with android webview so that it would work in my app as it is working in chrome/firefox etc.
What I tried: After digging deeper into this, I finally concluded that as android WebView
doesn't support Push Api (with the help of caniuse.com), clubbing of web push with mobile push using WebView
is not possible as of now. Am I right? Or is there any app which already does this? Is it possible somehow?
Ow, of course this is possible! I easily implemented push web notifications from one signal in my webview App using crosswalk.
Uses crosswalk, extends Main activity to XWalkactivity Put this on on create:
Yeah, you will have web push notifications working!!!
As I'm aware, it's not possible using only WebView .
The solution that worked for me was to find whether the website you want to display in the WebView uses WebSockets. If yes, the notification will probably be available in the according WebSocket communication. The workflow is following:
Determine WebSocket on the website. You can use Firefox "Inspect Code" and in "Network" tab filter out only WebSocket entries.
You can test connection to ws via various tools. Simple-WebSocket-Client for Firefox or command line tool. Simply provide URI to your WebSocket (
ws://domain.example/ws
).Implement WebSocket client in your application. There's been different posts on how to do that. I've used this lib to make it nice and clean.
Now you are receiving messages from server, such as notifications.
Parse them and do whatever you want.