Reputation: 449
Is there some way to set NotificationCompat.BigTextStyle() on the default Parse's push notification handler? When I send one push containing "alert" field, the sdk shows the notification with the default style and the text it's trimmed.
Upvotes: 1
Views: 450
Reputation: 1954
You have to customize your "data" payload. Instead of the usual
Parse.Push.send({
channels: [ "Giants", "Mets" ],
data: {
alert: "The Giants won against the Mets 2-3."
}
}, {
success: function() {
// Push was successful
},
error: function(error) {
// Handle error
}
});
You'll have to craft your payload to something like this for example:
var myData = {
action:"com.yourcompany.blahblah.UPDATE_SOMETHING", // take note of this!!!
message:"You are awesome",
somethingelse:3
};
// Note: some "data" field names are reserved
Parse.Push.send({
channels: [ "Mets" ],
data: myData
}, {
success: function() {
// Push was successful
},
error: function(error) {
// Handle error
}
});
You can see this in the docs: https://parse.com/docs/push_guide#options-data/JavaScript
And then, on your Android client:
1.) Remove these tags in your manifest file
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
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>
2.) Craft your own BroadcastReceiver (I suggest a WakefulBroadcastReceiver type), that then fires off an IntentService, to display the notification. This broadcast receiver listens to the action you specified earlier in your custom data payload:
<receiver
android:name="com.yourcompany.blahblah.MyCustomReceiver"
android:enabled="true"
android:exported="false" >
<intent-filter>
<action android:name="com.yourcompany.blahblah.UPDATE_SOMETHING" />
</intent-filter>
</receiver>
3.) In your IntentService (of course registered in your manifest file as well), you can then extract the "pushed" data as json from the Intent's extras, and craft however you want your Notification to appear:
@Override
protected void onHandleIntent(Intent intent) {
final Bundle extras = intent.getExtras();
final JSONObject json = new JSONObject(extras.getString("com.parse.Data"));
// keys matching your myData payload object names/keys
final String message = json.getString("message");
final int somethingelse = json.getInt("somethingelse");
// YOUR code to compose the Notification however you want it to appear follows here
EDIT:
Another method:
1.) Create a new class that extends ParsePushBroadcastReceiver (https://parse.com/docs/android/api/com/parse/ParsePushBroadcastReceiver.html)
2.) Override the methods particularly getNotification(Context context, Intent intent)
3.) compose your BigStyle notification from there
Upvotes: 1