【问题标题】:Parse.com: Sending a localized push notification to Android client - what does the client implementation look like?Parse.com:向 Android 客户端发送本地化推送通知 - 客户端实现是什么样的?
【发布时间】:2016-01-13 10:00:58
【问题描述】:

我希望完全按照in this question 的描述进行操作,但要发送到 Android 客户端。 Android客户端如何正确处理alert对象中的loc-keyloc-argsaction-loc-key参数?

云代码:

Parse.Push.send({
        where: pushQuery,
        data: {
            title: title,
            alert: {
                    "loc-key":"msg",
                    "loc-args":["John"],
                    "action-loc-key":"rsp"
            },
            type: type
        }
    }

Android 客户端如何正确处理这些键并本地化推送?我是否必须手动对 Parse 广播接收器进行子类化?

【问题讨论】:

    标签: android parse-platform push-notification android-notifications parse-cloud-code


    【解决方案1】:

    是的,你必须继承 Parse Broadcast 接收器

    首先,在清单中声明一个接收器

            <receiver android:name="com.example.PushReceiver" android:exported="false" >
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>
    

    然后你创建一个 ParsePushBroadcastReceiver 子类并重写 onReceive 方法。

        public class PushReceiver extends ParsePushBroadcastReceiver{
          @Override
          public void onPushReceive(Context context, Intent intent) {
    
        try {
            JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
    
             //This is where you get your values
              JSONObject alertObject = json.getJSONObject("alert");
    
        } catch (JSONException e) {
            e.printStackTrace();
        }
        }
    }
    

    【讨论】:

    • 还有更多工作要做。我花了一个小时左右的时间,我也必须重写 getNotification 方法——这很烦人,因为它构建了通知而不是将其留在 Builder 中。所以我不能修改它返回的 Notification 对象上的 alert 文本。唔。我可能只需要复制整个该死的方法并在那里进行警报本地化。为什么 Parse 让这件事变得如此复杂?
    • 顺便说一句,正确的覆盖方法是onPushReceive,而不是onReceive - 但感谢您为我指明了正确的方向。
    • 当然,我不知道为什么解析这么复杂,我已经用 GCM 做了几次,客户端部分更容易了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多