1

I'm looking to do exactly what's described in this question, but sending to an Android client. How does the Android client correctly handle the loc-key, loc-args and action-loc-key parameters in the alert object?

Cloud code:

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

How can the Android client correctly handle those keys and localize the push? Do I have to manually subclass the Parse broadcast receiver?

Community
  • 1
  • 1
Aphex
  • 7,390
  • 5
  • 33
  • 54

1 Answers1

1

Yes, you have to subclass the Parse Broadcast receiver

first, declare a receiver in your manifest

        <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>

Then you create a ParsePushBroadcastReceiver subclass and override the onReceive method.

    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();
    }
    }
}
wnieves19
  • 550
  • 4
  • 16
  • There's more work than that. I'm an hour or so into this and I have to override the `getNotification` method too - which is annoying to do, because it builds the notification rather than leaving it in a Builder. So I can't modify the `alert` text on the Notification object it returns. Hmm. I might have to just copy the whole damn method and do the alert localization in there. Why does Parse make this so complicated? – Aphex Jan 13 '16 at 22:10
  • By the way, the correct method to override is `onPushReceive`, not `onReceive` - but thanks for pointing me in the right direction. – Aphex Jan 13 '16 at 22:11
  • Sure, I don't know why is so complicated with parse, I've done it with GCM a couple time and the client part has been much easier – wnieves19 Jan 14 '16 at 12:36