I have in my android application the OneSignal service working correctly, so far so good. I want to make some modifications to my SharePreference every time I receive a message. I was able to do this while the application is in the foreground, however in the background the action does not work. I would then like to help me solve this problem. Here is the code that works at first prano
public class mIntentService extends IntentService {
public mIntentService() {
super("notification");
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
// OneSignal Initialization
OneSignal.startInit(MyApplication.getAppContext())
.setNotificationReceivedHandler(new NotificationReceivedHandler())
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
Log.i("notification", "O IntentService foi iniciado");
}
public class NotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
@Override
public void notificationReceived(OSNotification notification) {
//Essa é a função após receber a notificação
LibraryIO io = new LibraryIO(getApplicationContext());
io.setBooleanIO("iconNotificationNews", true);
Log.i("iconNotificationNews", "iconNotificationNews chamadado");
}
}
}
Please note that I tried to play on a service, but I still do not understand how it works.