我嘗試使用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