How to add notification in webview? - android

I have created a webview app which working is perfectly fine with a website say xyz.com
The app is made for small scale purpose and for personal use. (Not uploaded in play store)
Generally when I change some content in the website - Index.html(say) the app also gets update as it loads the updated url.
I want to create a notification that whenever I change the content user gets a notification in their notification bar say (today event - abc ) and when they click that notification it opens the app to see what got updated.
How to create such notifications?

You need to first register your user and get the gcm registration id and save it on your server. Then you can implement notification system present in android like this http://developer.android.com/guide/topics/ui/notifiers/notifications.html
Whenever you change your content just send a notification to all the user base and your work is done. Thanks

You can add bootstrap modal in index.html page. and add content on that model

Related

How to pass data from background android service to react-native

I am building an react-native app. I have a background android service that receives a push notification. I need to store the notification information(title, description...) on a react-native database or in asyncstorage... because in my app I have a page that shows all the notifications. I need that If my app is on background and i receive a notification, when the user open the app the page shows this information. How I can do this?
I try to store the notification on the same database that react-native uses but I can't store the data on the android service. Please, help me.
Did you try exploring these.
componentWillMount() {
Linking.addEventListener("url", this.handleOpenURL);
OneSignal.addEventListener("ids", this.onIds);
OneSignal.addEventListener("received", this.onReceived);
OneSignal.addEventListener("opened", this.onOpened);
}
And in oneReceived event listener you can store data in async storage received from push notification.
onReceived(data) {
this.props.setData(data);
}
In set data you can have your logics to store data.Well i must say push notifications are not used to fetch data and to store and then to render.These provide just little information to open specific screen .Like i received a notification related to deals.Then pressing upon will automatically opens deals screen through linking not the home page of app.For your case you can send the request on that specific page to fetch data.
Yes, but when you close the app and after this, someone sends one push notification, the event received and opened etc don't do nothing. I tried to make a custom native module that receives this info and try to send an Event. I followed this guide:
https://facebook.github.io/react-native/docs/native-modules-android#sending-events-to-javascript
But it don't works, always returns "sendEvent called before bundle loaded" java.lang.NullPointerException.

Foreground app notification is almost empty, background app gets notification but without custom data

I'm working on an Android app in Kotlin and I want to send notification in order to click on it and open a custom view.
I've implemented notification thanks to Firebase. I can send notification thans to Firebase, but the notification are well displayed (with the right icone (= triangle), the right title and the right message) only if the app is in background, but the custom data (key => val) provided in firebase are not detected.
For the foreground app, if I send the notification from Firebase, I can display the custom data (key => val), but the notification doesn't have title, message or custom icone (it has the square/rounded icone)
Instead of showing all my code, I prefere to give you the link I've followed.
https://www.android4dev.com/firebase-pushnotification-android/
I want to have the same result on both side so I can get the custom data.
See the result :
There are two types of FCM messages and the behaviour changes based on it.
Notification messages (these are handled by the SDK automatically)
Data messages (handled by the app)
Use notification messages when you want FCM to handle displaying a
notification on your client app's behalf. Use data messages when you
want to process the messages on your client app.
https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
I think that you should use data messages instead of notification messages to have a consistent behaviour.

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.
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)

Clear notifications using OneSignal and Ionic on Android

In my app, users can create posts that can generate alerts to other users based on the content. The server receives the new post and sends notifications using the OneSignal API. No problems there, all notifications arrive to all intended users.
When the users receive the notification and they click on the newly arrived notification, the app opens and the notification dissappears. Excelent.
However, when a user gets the notification but enters the app without clicking on the notification, I also want the notifications gone.
How can I clear all my app notifications? I am using OneSignal-Cordova-SDK
.
Thank you
Ok, so I found the solution myself. I had to manually add code to the OneSignal.js included in the plugin to access the clearOneSignalNotifications() function.
I solved by adding this to a page that loads when the app resumes:
window["plugins"].OneSignal.clearOneSignalNotifications();
And in index.html tag:
<!-- ONESIGNAL WEB PUSH -->
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
<script>
var OneSignal = window.OneSignal || [];
</script>

Displaying a message with a website address upon first install of Android app

This may be a noob question in Android porgramming but here goes..
I have an apk setup on my website as a link to say www.manusandme.com/test.apk. I would like to capture this website address on which the link is and display it to the user once the app is installed and opened for the first time.
Say once the user installs app and opens it for the first time, on the home screen it displays. Hi, you just got this app from www.manusandme.com. instead of say Hello World!
User goes to site ----> Clicks on link ---> APK is downloaded to phone ---> User installs it ---> THen user opens it ----> Message with website on which user clicked needs to be displayed on home screen.
Is this possible in android? Kindly advise.
Thanks in advance for your help.
With regards,
Manus
Yes, You can save in you SharedPreferences some flag informing that this message was already shown. For example in you main activity do this:
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean wasShown = preferences.getBoolean(Const.Config.MESSAGE_WAS_SHOWN, false);
then if wasShown is false, then show your message and after showing it update this preference to true.
Hi yes its possible to pass the website url with the parameter attached with its url.
for example :www.your_url.com/Firsttimeapp/IMEI_no=122412342355345
And create a separate catching on the website that only add's the New IMEI no of the mobile.
The Problem with the shared preference will that once any clear's the app data it will again send an entry on the server side.

Categories

Resources