【问题标题】:Using JSON Parse push to open fragment使用 JSON Parse 推送打开片段
【发布时间】:2015-06-06 00:47:39
【问题描述】:

我已经成功地让 iOS 应用程序根据存储在 JSON 推送中的值打开某些视图,我现在正尝试在我们的 android 应用程序中做同样的事情。

这是正在发送的消息:

{
 "alert": "Test Push ",
 "title": "New Test push",

 "view": "circles"
}

有很多关于堆栈溢出的问题,但恐怕我不明白特定代码 sn-ps 可以去哪里,或者如何让它打开一个片段而不是根活动。

我的问题是,在不要求为我编写所有代码的情况下,我需要使用哪些函数、调用和类来实现这一点?

【问题讨论】:

  • 您想根据推送中的数据打开不同的视图,还是需要用不同的数据打开相同的视图?
  • 根据推送不同的视图

标签: android json android-fragments parse-platform android-json


【解决方案1】:

我用这个解决方案实现 Parse Push:Open activity by clicking on the push notification from Parse

最好的办法是编写一个 Intent 阅读器来检测 Activity 是否是从单击推送消息开始的。上面的链接为您提供了一个示例:

try {
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
        String jsonData = extras.getString("com.parse.Data"); // Get data from Parse Push json
        JSONObject json;
        json = new JSONObject(jsonData);
        String view = json.getString("view");
        // Write your logic to start the fragment/activity
    }
} catch (JSONException e) {
    e.printStackTrace();
}

【讨论】:

    猜你喜欢
    • 2016-10-03
    • 1970-01-01
    • 2015-07-03
    • 1970-01-01
    • 1970-01-01
    • 2017-11-11
    • 2014-11-27
    • 1970-01-01
    • 2016-03-13
    相关资源
    最近更新 更多