我有一个带OneSignal的Wordpress网站作为推送通知服务,但我有一个需要:我想在用户打开通知时在我的Android应用中获取帖子ID,以确定要打开哪个活动?
答案 0 :(得分:0)
好吧,我实际上发现了一个黑客。这就是我做的:
public void notificationOpened(OSNotificationOpenResult result) {
OSNotificationAction.ActionType actionType = result.action.type;
String slug = getWebMediaName(result.notification.payload.launchURL);
String notificationBody = (result.notification.payload.body != null) ?
result.notification.payload.body : "";
}
我发现只要您在服务器上启用了REST API,我也可以在wordpress上找到一个slug的帖子
private String getWebMediaName(String val){
//split the string and then find your slug which is usually the last
//characters after the "/" forward slash character
}
答案 1 :(得分:0)
如何从响应中获取post id作为接收启动URL和正文?
示例回复是
result {"action":{"type":0},"notification":{"isAppInFocus":false,"shown":true,"androidNotificationId":-216570404,"displayType":0,"payload":{"notificationID":"a3d651a1-e67b-4c82-ada8-c5f03e8b08f0","title":"OdishaReporter","body":"???????? ??????? ?? ???????? ???????","launchURL":"http:\/\/odishareporter.in\/odisha\/protest-in-delhi-on-kundali-issue\/","lockScreenVisibility":1,"fromProjectNumber":"995873670600","priority":0,"rawPayload":"{\"google.sent_time\":1518685044953,\"google.ttl\":259200,\"custom\":\"{\\\"u\\\":\\\"http:\\\\\\\/\\\\\\\/odishareporter.in\\\\\\\/odisha\\\\\\\/protest-in-delhi-on-kundali-issue\\\\\\\/\\\",\\\"i\\\":\\\"a3d651a1-e67b-4c82-ada8-c5f03e8b08f0\\\"}\",\"from\":\"995873670600\",\"alert\":\"???????? ??????? ?? ???????? ???????\",\"title\":\"OdishaReporter\",\"google.message_id\":\"0:1518685044961958%6229cc87f9fd7ecd\",\"notificationId\":-216570404}"}}}