How to override onPushReceive() of ParsePushBroadcastReceiver?

后端 未结 2 1344
傲寒
傲寒 2020-12-29 16:18

I am using push notification service of Parse.com. According to the doc:

override onPushReceive to trigger a background operation for \"silent\" pus

2条回答
  •  温柔的废话
    2020-12-29 16:34

    You can use the intent extra parameter "action" to call your intent to handle whatever you want.

    Original onPushReceive source:

    protected void onPushReceive(Context context, Intent intent) {
        JSONObject pushData = null;
    
        try {
            pushData = new JSONObject(intent.getStringExtra("com.parse.Data"));
        } catch (JSONException var7) {
            Parse.logE("com.parse.ParsePushReceiver", "Unexpected JSONException when receiving push data: ", var7);
        }
    
        String action = null;
        if(pushData != null) {
            action = pushData.optString("action", (String)null);
        }
    
        if(action != null) {
            Bundle notification = intent.getExtras();
            Intent broadcastIntent = new Intent();
            broadcastIntent.putExtras(notification);
            broadcastIntent.setAction(action);
            broadcastIntent.setPackage(context.getPackageName());
            context.sendBroadcast(broadcastIntent);
        }
    
        Notification notification1 = this.getNotification(context, intent);
        if(notification1 != null) {
            ParseNotificationManager.getInstance().showNotification(context, notification1);
        }
    
    }
    

    And no notification if no "alert" or "title" extra in the intent.

    So you do not need to extend any class at all for silent push updates...

提交回复
热议问题