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

Not calling OnNotificationOpened event when app in terminated -Android #197

Closed
arvindrajachourasiya opened this issue Nov 30, 2018 · 11 comments

Comments

@arvindrajachourasiya
Copy link

arvindrajachourasiya commented Nov 30, 2018

When app in terminated (Killed from task-bar), And sending notification to app. When I tap on notification, OnNotificationOpened event not getting called. App navigating to MainPage

CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
	var data = p.Data;
	if (p.Data.ContainsKey("color"))
	{
	Device.BeginInvokeOnMainThread(() =>
	{
		Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new Page1()
		{
			BackgroundColor = Color.FromHex($"{p.Data["color"]}")
		});
	});
	}
};

For more information visit this https://stackoverflow.com/questions/53594512/specific-view-not-opening-on-notification-tap-when-app-in-foreground

Bug Information

Version Number of Plugin:2.3.5
Device Tested On: Moto c plus
Simulator Tested On:
Version of VS: 15.8
Version of Xamarin: 3.4 XF
Versions of other things you are using:

Steps to reproduce the Behavior

Use code above & send notification when app in foreground

Expected Behavior

App should navigate to Targated screen when tapping on notification

Actual Behavior

When tapping on notification app going to MainPage

Code snippet

Screenshots

@Mikilll94
Copy link

In my case, OnNotificationOpened is not called when on Android when the app is in the foreground. When the app is in the background or its killed everything works fine.

@arvindrajachourasiya
Copy link
Author

@Mikilll94 - Foreground means app killed from taskbar. Background means app open in taskbar. So when app in foreground are you getting notifications?

@Mikilll94
Copy link

Foreground means app opened - not killed from taskbar. I am receiving notifications but the method OnNotificationOpened is not called on Android when the app is in the foreground.

@arvindrajachourasiya
Copy link
Author

When app closed from task manager is it called background? & when app just closed(but open in task manager) what is called?

@arvindrajachourasiya arvindrajachourasiya changed the title Not calling OnNotificationOpened event when app in foreground -Android Not calling OnNotificationOpened event when app in terminated -Android Dec 4, 2018
@raymondjstone
Copy link

'Not calling OnNotificationOpened event when app in terminated' is that not a known cloud messaging issue. As I recall it depends the the phone model and OS version but lots of them do not have inbuilt support for FCM unlike GCM which was more supported. So some phones will open the app when a notification is clicked and the app was killed previously and other phones will not.

@arvindrajachourasiya
Copy link
Author

@raymondjstone - Thank you for your input. I am using moto c plus device with android version 7.0. On the same device I am checking notifications of Xamarin.android(FCM) working all good. So this is not the issue of device, fcm, gcm and device. It is probably the issue of plugin or I might missing something.

@raymondjstone
Copy link

That device is one which I believe does have an issue with handling FCM notifications when the app has been killed. Many if not most phones do. If you look on the FCM support pages there used to be something there that confirmed this was an FCM issue (and that GCM did not have the same level of problem)

@arvindrajachourasiya
Copy link
Author

@raymondjstone - As I mentioned above that same device is working fine Xam.Droid. Last year I developed push notifications, still using today that product. So I am pretty sure it is not the device :).

@raymondjstone
Copy link

Well if you insist that it is not your device or the FCM known issue then there is nothing else I can suggest, this is what I have in my apps help for this issue but since it;s not your device this will not help you but may help others

Push notifications not working on your Android app?

Certain Android devices might have some problems receiving push notifications when the myAberdeenshire app is closed. Whether you run into this problem will depend on what device you're using.
To ensure you keep receiving push notifications, you'll need to set your device so that it will auto-start the app when a new notification arrives.

We've collected some instructions and resources below, to help you troubleshoot this problem.

IMPORTANT NOTE: The exact steps for this process will vary depending on your device model. We recommend using the information here as a starting point. Some Googling with your precise model details should find instructions specific to your device.

Huawei
Make sure app is on the list of protected apps. Open System settings, then Advanced Settings, then Battery Manager, and finally Protected apps. Enable the toggle next to app to allow it to keep running even after the screen is turned off.

Lenovo:
Enable the auto-start setting for the app app. Open Settings and click Power Manager and then Background app management. Flip the Allow auto-start toggle for the app.

OnePlus:
Make sure app is in the auto-launch list. Open up Settings and click Apps, the gear icon, and then Apps Auto-launch. Find app in the list and toggle it on to enable autolaunch.

Oppo:
Make sure app is on the list of allowed start-up apps. Open Security Center, click Privacy Permissions, then Startup Manager, and then allow App to start-up in the background.

Samsung:
If you're using the app on a Samsung device, there are a few steps to take:
Switch off battery optimisation for app. Open Settings, then Apps, then the three dots on the upper right corner, then Special Access, then Optimize battery usage. From here, tap on the dropdown menu that says 'Apps not optimized’, then switch it to all apps and then switch off battery optimisation for the App.

Vivo:
Enable the auto-start setting for the app. Open iManager, click App Manager, then Autostart manager, and then allow App to auto-start in the background.

Xiaomi
Enable autostart for the . Open up Security and click through to Permissions and Autostart. Make sure app is enabled.

NOTE:
If you've tried the relevant options above but the problem persists, you can also try making sure that the app is not optimized for Doze feature (battery saving). You can find this setting on most devices by clicking Settings, then Battery, and then Battery Optimization. Make sure app is on the list of apps excluded from optimization.

@arvindrajachourasiya
Copy link
Author

@Mikilll94 - Thank you for your detailed information. As you said above you are able to open specific view when app terminated. Can you please give me sample repository to just compare where I am making mistake.

@rdelrosario
Copy link
Member

How is the payload being sent?

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