【发布时间】:2014-03-31 12:50:04
【问题描述】:
我正在使用 Parse SDK 在我的 Android 应用中接收推送通知。我的后端发送一个 JSON 格式的字符串,其中包含要在通知栏中显示的推送通知的内容。
我想要做的是解析这个 JSON,并根据它的内容,将用户带到应用程序的不同部分(活动)。我能够很好地接收和解析 JSON,但是如何处理用户点击通知栏中的通知时执行的实际操作?
我知道我可以配置 Parse SDK 在我订阅特定频道时打开不同的活动,如下所示:
PushService.subscribe(this, "testing", ActivityA.class, R.drawable.ic_push);
PushService.subscribe(this, "testing2", ActivityB.class, R.drawable.ic_push);
// etc
但这并没有真正帮助我,因为在我真正收到推送通知并解析 JSON 之前,我不知道要打开哪个 Activity。所以,我正在寻找的是这样的:
public class PushReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
try {
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
if(json contains id = 0) {
// open ActivityA when the user opens this notification
} else if(json contains id = 1) {
// open ActivityB when the user opens this notification
}
} catch (JSONException e) {
Log.d("", "JSONException: " + e.getMessage());
}
}
}
任何想法如何使用 Parse 来完成?谢谢。
【问题讨论】:
标签: android push-notification parse-platform