【问题标题】:How to fetch data from OneSignal Wordpress post in Android app?如何从 Android 应用程序中的 OneSignal Wordpress 帖子中获取数据?
【发布时间】:2018-01-17 09:14:07
【问题描述】:

我有一个使用 OneSignal 作为推送通知服务的 Wordpress 网站,但我有一个需求:每当用户打开通知时,我想在我的 Android 应用中获取帖子 ID 以确定要打开哪个 Activity?

【问题讨论】:

    标签: android wordpress push-notification onesignal


    【解决方案1】:

    如何从响应中获取帖子 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}"}}}
    

    【讨论】:

      【解决方案2】:

      嗯,我实际上找到了一个解决这个问题的方法。这就是我所做的:

       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 上找到一个带有 is 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
      }
      

      【讨论】:

        猜你喜欢
        • 2014-02-09
        • 1970-01-01
        • 2018-01-31
        • 1970-01-01
        • 1970-01-01
        • 2023-03-05
        • 1970-01-01
        • 2023-01-18
        • 1970-01-01
        相关资源
        最近更新 更多