Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push Notifications in WebView android app

I have a requirement where I want to send push notifications to the user.
For example

the app will have 2 users. If user 1 send a friend request to user 2 then user 2 should get a notification like " You got friend request from user 1" and when user 2 clicks on that notification he should able to see the user 1 profile.

I know how to do all these with the activities but here I am using web view, so please help me to solve with this. Any help is appreciable.

like image 235
Jz Another Dev Avatar asked Aug 18 '26 09:08

Jz Another Dev


1 Answers

You can always access your Java code trough javascrtipt running on the web page your WebView is presenting. You can define a Java method (which sends the notification through your backend) and call it from your custom javascript.

Take a look at https://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object,%20java.lang.String)

like image 78
Eddie Lopez Avatar answered Aug 19 '26 23:08

Eddie Lopez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!