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

[question]: Hi I'm trying to handle push notification events coming from a messaging service of my company, what happens is that the push arrives and I want that when I click it redirects my app to the main screen, ActivityStart example?? #2206

Closed
1 task done
RuHuaytaMars opened this issue Oct 21, 2024 · 1 comment

Comments

@RuHuaytaMars
Copy link

RuHuaytaMars commented Oct 21, 2024

How can we help?

@keep
public class OSDataReceiver implements INotificationServiceExtension, HttpObtenerServiciosV3.InterfaceNotification {
// *****************************************
// ***************** PUSH NOTIFICACIONES ******************
// *****************************************
private final int PROCESS_CERRAR_SESSION = 101;

@Override
public void onNotificationReceived(@NonNull INotificationReceivedEvent event) {
	try {
		Log.e("OSDataReceiver", "onNotificationReceived");
		IDisplayableMutableNotification notification = event.getNotification();
		JSONObject data = notification.getAdditionalData();
		String jsonData = data.toString();
		Log.e("SDOneSignalJSON", "id = " + notification.getNotificationId() + " - " + jsonData);
		if (!jsonData.isEmpty()) {

			event.preventDefault(true);
			BeanNotificationOS beanOneSignalPush = BeanMapper.fromJson(jsonData, BeanNotificationOS.class);
			Log.e("SDOneSignalPush", "Request : " + BeanMapper.toJson(beanOneSignalPush));
			//	new HttpGetNotification(this, this).execute(beanOneSignalPush);
			// TODO -  ya no se usara la descarga
			Context context = ApplicationClass.getInstance();
			new HttpObtenerServiciosV3(context, this, beanOneSignalPush).execute();
			//initNotification(beanOneSignalPush);
		}
		// Return true to stop the notification from displaying.
		//event.getNotification().display();
	} catch (Exception ex) {
		ex.printStackTrace();
	}
}

My Notification Service

SDK version : One Signal 5.1.20

Code of Conduct

  • I agree to follow this project's Code of Conduct
@jinliu9508
Copy link
Contributor

Hello @RuHuaytaMars, if I understand correctly, you want to start a specific activity when the notification is clicked. If that's the case, I believe you can add a foregroundLifecycleListener to the notification and implement the 'onWillDisplay' method. This way, when your app is opened upon clicking the notification, you can start the desired activity.

Here is more info for 'foregroundLifecycleListener'

Let me know if you have further questions, I will be glad to help!

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

2 participants