Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App in background: Notification is received but app is closed on clicking notification tray #31

Closed
apurvaAndroid opened this issue Oct 25, 2018 · 15 comments
Assignees

Comments

@apurvaAndroid
Copy link

No description provided.

@apurvaAndroid
Copy link
Author

Working fine in below scenarios:
1.App is killed and push notification arrives.
2.App is in foreground and push notification arrives.

Not working when App is in background and push notification arrives.

@m1ga
Copy link
Collaborator

m1ga commented Oct 25, 2018

please provide some code. For me its working fine:
http://migaweb.de/ti_push.mp4
Second push is arriving in background and clicking the notification brings the app to the front and displays the data

@m1ga m1ga self-assigned this Oct 25, 2018
@apurvaAndroid
Copy link
Author

                     var core = require('firebase.core');
		var fcm = require('firebase.cloudmessaging');
		var isAndroid = Ti.Platform.osname === 'android';
		
		// Configure core module (required for all Firebase modules)
		
		core.configure({
			APIKey:'YourAPI KEY',
			googleAppID : 'APPID',
			GCMSenderID : 'GCMSenderID',
			applicationID: "applicationID"
	    });

	    	fcm.addEventListener('didRefreshRegistrationToken', onToken);
		
		// Called when direct messages arrive. Note that these are different from push notifications
		fcm.addEventListener('didReceiveMessage', onMessage);
		
		fcm.registerForPushNotifications();
		
		 fcm.addEventListener('didReceiveMessage', function (e) {
            //Ti.API.info('!!!!!!Message ', JSON.stringify(e));
          
            
			
   		 });
		
		function onToken(e) {
		    Ti.API.info('Token', e.fcmToken);
		    Alloy.Globals.DeviceToken = e.fcmToken;

		}
		
		function onMessage(e) {
		    Ti.API.info('Message', e.message);
		}

		isAndroid && fcm.createNotificationChannel({
			  sound: 'warn_sound',
			  channelId: 'general',
			  channelName: 'General Notifications',
			  importance: 'high' //will pop in from the top and make a sound
			});

	     if (fcm.fcmToken !== null) {
		 Alloy.Globals.DeviceToken = fcm.fcmToken;

		    Ti.API.info('FCM-Token', fcm.fcmToken);
		} else {
		    Ti.API.info('Token is empty. Waiting for the token callback ...');
		}

		 fcm.subscribeToTopic('testTopic');

format of payload

{"to":"fvfEay1N-ss:APA91bFx1UTmDwGgpa0Oic63O48_PhMN7xi8h1E9FAy353T4wm-v4VKvyablAtVqlj1kEWcsmfp6qy-1cbDa7pXIIQi2Blc-P7dQhHPb71ciieLvneYTMZRvKXB7S1xPqPV8GqzFkepz","notification":{"title":"Working Good","body":"[add your message]"} "data":{ "type":"req"},"priority":"high"}

@m1ga
Copy link
Collaborator

m1ga commented Oct 25, 2018

try removing the 2nd fcm.addEventListener('didReceiveMessage', function (e) {...}

and use lastData since you are sending a notification and data.

@apurvaAndroid
Copy link
Author

apurvaAndroid commented Oct 25, 2018

Removed fcm.addEventListener('didReceiveMessage', function (e) {...}
and handle data in onMessage method
function onMessage(e) {
Ti.API.info('ON __ Message', JSON.stringify(e));
}
Done the changes still facing same issue.

@m1ga
Copy link
Collaborator

m1ga commented Oct 25, 2018

btw: what is not working? You've just said Not working when App is in background and push notification arrives.
Is the app not opening? Do you not get the data (again use lastData)?

@apurvaAndroid
Copy link
Author

apurvaAndroid commented Oct 25, 2018

When the app is in the background I received a push notification but the app crashed when I click on notification tray (app not opening)

@m1ga
Copy link
Collaborator

m1ga commented Oct 25, 2018

so anything in the log when it crashes?

@apurvaAndroid
Copy link
Author

apurvaAndroid commented Oct 26, 2018

10-26 12:02:07.371: W/FirebaseMessaging(6104): Error while parsing timestamp in GCM event
10-26 12:02:07.371: W/FirebaseMessaging(6104): java.lang.NumberFormatException: s == null
10-26 12:02:07.371: W/FirebaseMessaging(6104): at java.lang.Integer.parseInt(Integer.java:570)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at java.lang.Integer.valueOf(Integer.java:794)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at com.google.firebase.messaging.zzd.zzb(Unknown Source:60)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at com.google.firebase.messaging.zzd.zzh(Unknown Source:84)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at com.google.firebase.messaging.FirebaseMessagingService.zzo(Unknown Source:35)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at com.google.firebase.iid.zzf.zza(Unknown Source:38)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at com.google.firebase.iid.zzh.zzJO(Unknown Source:80)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at com.google.firebase.iid.zzh.zza(Unknown Source:29)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at com.google.firebase.iid.FirebaseInstanceIdInternalReceiver.onReceive(Unknown Source:41)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at android.app.ActivityThread.handleReceiver(ActivityThread.java:3392)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at android.app.ActivityThread.-wrap18(Unknown Source:0)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1780)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at android.os.Handler.dispatchMessage(Handler.java:105)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at android.os.Looper.loop(Looper.java:164)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at android.app.ActivityThread.main(ActivityThread.java:6944)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at java.lang.reflect.Method.invoke(Native Method)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
10-26 12:02:07.371: W/FirebaseMessaging(6104): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
10-26 12:02:07.372: W/FirebaseMessaging(6104): Unable to log event: analytics library is missing


flutter/flutter#19004

@apurvaAndroid
Copy link
Author

Who is facing background notification issue please use below module

firebase.cloudmessaging-android-1.5.0.zip
TI.SDK 7.1.1

@m1ga
Copy link
Collaborator

m1ga commented Oct 31, 2018

What did you change? Anything that can be included in the public module?

@apurvaAndroid
Copy link
Author

Yes, I have changed the native code in a module for notification channel.
I am facing the issue when I pass notification key in payload and if I removed notification key then notification not coming while app in the background.
So now I only need to pass data in payload no notification key and receiving notification tray when the app in the background
Also when the app in background(running not killed) OnMessageRecieved gets the call previously it is not getting a call when the app in the background. 

@antonioduran
Copy link

Hey hello @apurvaAndroid . This module version (https://github.com/hansemannn/titanium-firebase-cloud-messaging/files/2534820/firebase.cloudmessaging-android-1.5.0.zip) in my case it is working sending push notifications through onesignal, the other version of the module like (Android 1.4.0) is not working at all - but ned to know whether you found something tho get the data when the app is closed, and the push notification arrives. I mean to get the information of the payload when we click on the push notification from the notification tray. I appreciate any information. Thank you.

Repository owner deleted a comment from antonioduran Feb 27, 2019
@apurvaAndroid
Copy link
Author

@antonioduran no I have not found payload on clicking of notification tray.

@aseemk98
Copy link

Even I'm getting the same error when I'm trying to log the contents of the message. When, I close the app, the message shows up in the notification tray but the error "Unable to log event: analytics library is missing" is displayed in the logcat. How do I fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants