I want to directly open the specific fragment through using title from notification.
In my BaseApplication class I tried this code and i was able to set the flag as i wanted.
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
// OneSignal Initialization
OneSignal.initWithContext(this);
OneSignal.setAppId(ONESIGNAL_APP_ID);
OneSignal.setNotificationOpenedHandler(result -> {
Log.d("TAG", "notificationOpened: " + result.toString());
if (result.getNotification().getTitle().toLowerCase().equals("first")) {
fromNotifFlag = "first";
} else if (result.getNotification().getTitle().toLowerCase().equals("second")) {
fromNotifFlag = "second";
}
});
I used this flag to open the fragment in MainActivity(onCreate).
if (BaseApplication.fromNotifFlag.equals("first")) {
Navigation.findNavController(getCurrentFocus()).navigate(R.id.action_mainfragment_to_secondFragment);
}
if (BaseApplication.fromNotifFlag.equals("second")) {
Navigation.findNavController(getCurrentFocus()).navigate(R.id.action_mainfragment_to_secondFragment);
}
It didn't work for some reason. How can i listen the notification and open a specific fragment?
The code i shared is actually working but i used the second part in my mainFragment instead of mainActivity.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.