我尝试使用OneSignal制作聊天应用程序。而且我希望listview在通知即将到来时设置适配器。如果我使用setNotificationOpenedHandler
它的工作,但我应该点击提示通知,使列表视图设置适配器。问题是,我不希望点击提示/通知来设置适配器listview,所以我使用setNotificationReceivedHandler
,但不工作,没有改变任何东西。OneSignal setNotificationReceivedHandler无法设置适配器
这种开放式处理器(工作)
OneSignal.startInit(this)
.setNotificationOpenedHandler(new OneSignal.NotificationOpenedHandler() {
@Override
public void notificationOpened(OSNotificationOpenResult result) {
ArrayList<HashMap<String, String>> dt = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("a", "testing 2");
dt.add(map);
ChatMessageAdapter adap = new ChatMessageAdapter(ChatActivity.this, dt);
listView = (ListView) findViewById(R.id.listViewChat);
listView.setAdapter(adap);
}
})
.init();
这对于接收处理程序(不行)
OneSignal.startInit(this)
.setNotificationReceivedHandler(new OneSignal.NotificationReceivedHandler() {
@Override
public void notificationReceived(OSNotification notification) {
ArrayList<HashMap<String, String>> dt = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("a", "testing 1");
dt.add(map);
ChatMessageAdapter adap = new ChatMessageAdapter(ChatActivity.this, dt);
listView = (ListView) findViewById(R.id.listViewChat);
listView.setAdapter(adap);
}
})
.init();
我无法重现任何问题'notificationReceived'不射击。确保你从Application类的'onCreate'调用'OneSIgnal.startInit(..)'而不是一个Activity。 – jkasten