Parse - Android - 在默认推送通知中修剪的文本

时间:2014-12-03 20:55:45

标签: android text parse-platform push-notification string-length

有没有办法在默认的Parse推送通知处理程序上设置NotificationCompat.BigTextStyle()? 当我发送一个包含“alert”字段的推送时,sdk会显示默认样式的通知以及修剪它的文本。

1 个答案:

答案 0 :(得分:1)

您必须自定义“数据”有效负载。而不是通常的

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
  }
});

你必须将你的有效载荷制作成这样的东西,例如:

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
  }
});

您可以在文档中看到这一点:https://parse.com/docs/push_guide#options-data/JavaScript

然后,在您的Android客户端上:

1。)删除清单文件中的这些标签

<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。)制作你自己的BroadcastReceiver(我建议使用WakefulBroadcastReceiver类型),然后触发IntentService,以显示通知。此广播接收器侦听您在自定义数据有效内容中先前指定的操作:

<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.。)在您的IntentService中(当然也在您的清单文件中注册),然后您可以从Intent的附加内容中提取“推送”数据作为json,然后您希望出现您的通知:

@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

修改

另一种方法:

1。)创建一个扩展ParsePushBroadcastReceiver(https://parse.com/docs/android/api/com/parse/ParsePushBroadcastReceiver.html)的新类

2.。)覆盖方法,尤其是getNotification(上下文上下文,意图意图)

3.。)从那里撰写你的BigStyle通知