![](/img/trans.png)
[英]Android Grouped Notification (from OneSignal) crashes app when trying to open
[英]Android OneSignal , open specific fragment from notification
我想通过使用通知中的标题直接打开特定片段。
在我的 BaseApplication class 中,我尝试了此代码,并且能够根据需要设置标志。
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";
}
});
我使用此标志在 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);
}
由于某种原因它没有工作。 如何收听通知并打开特定片段?
我共享的代码实际上是有效的,但我在 mainFragment 中使用了第二部分而不是 mainActivity。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.