我正在使用Parse SDK在我的Android應用中接收推送通知。我的後端發送一個JSON格式的字符串,並在推送通知的內容中顯示在通知欄中。使用Parse響應推送通知
我想要做的就是解析這個JSON,並根據它的內容,把用戶帶到應用程序的不同部分(Activities)。我能夠接收和解析JSON,但是如何處理當用戶點擊通知欄中的通知時執行的實際操作?
我知道我可以配置解析SDK開闢不同的活動時,我訂閱特定信道,這樣的:
PushService.subscribe(this, "testing", ActivityA.class, R.drawable.ic_push);
PushService.subscribe(this, "testing2", ActivityB.class, R.drawable.ic_push);
// etc
但是,這並不能真正幫助我,因爲我不會知道打開哪個活動,直到我實際收到推送通知並解析JSON。所以,我正在尋找的東西是這樣的:
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可以實現這一點?謝謝。