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.
Related
I am using react native and redux-persist to build an application and I have push notification features (FCM data messages). So in order to be able to get notifications when app is in background I am using below code
AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', message =>
bgMessaging.bind(message, store, persistor),
);
basically a taks that runs in headless js my bgMessaging callback looks like below:
export default async (store, persistor, notif) => {
//notif -- is the notifications that i get
// store is the redux store peristed
//persistor is the corresponding persistor from redux-persistor
// update store logic is here
return Promise.resolve();
};
The problem is that the store I get is not the one I have persisted while app was in foreground.
Also if modify the store it is not picked by the app when launched.
How can I get the persisted store in this callback and how can Update it , so that it is it is reflected back when app launches.
I have already gone through few links as below but none of them solve the exact problem
link1
link 2
I am working on an ionic application and need to implement push notifications using the back end API's developed in .NET.
While going through few blogs I found fire base API's and was able to complete a POC using Firebase. However the notification did not show when the app was in foreground.
I am not sure how to consume .NET API's to get the push messages. Can we achieve this without using Firebase. Please suggest. Thanks !
It is normal so that notification not show on forground using firebase notifications.
this.firebase.onNotificationOpen().subscribe( (msg) => {
if (this.platform.is('ios')) {
this.presentToast(msg.aps.alert);
//here notfication in ios
} else {
this.presentToast(msg.body);
//here notfication in android
}
});
This will trigger a toast of notification in foreground. If you want it as notfication, use local notfication and set the msg.body details as it should be shown inside the local notfication.
And as an advice, use onesignal notfication since it contains better features plus easier and more flexible.
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.
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)
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