2014-12-03 27 views

回答

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(在你的清單文件,以及註冊課程),然後你可以提取的「推」數據從意向的額外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.)從那裏

+0

撰寫BigStyle通知一個新的類我知道這一點,我正在使用該功能。但是,當您從Parse平臺發送簡單推送時,默認有效內容將包含默認字段「alert」。我的問題是指出,我需要告訴Parse可以使用BigContentView的默認處理程序。或者,如果這是不可能的,重寫默認處理程序,但我還沒有找到這樣做。 – 2014-12-05 01:27:14

+0

我看到了,我更新了我的答案,嘗試了另一種方式(仍然使用默認有效載荷) – alpinescrambler 2014-12-05 16:28:06

+0

我會盡力讓您知道,謝謝。 – 2014-12-08 19:48:04