1

我正在尋找正確的描述in this question,但發送到Android客戶端。 Android客戶端如何正確處理alert對象中的loc-key,loc-argsaction-loc-key參數?Parse.com:向Android客戶端發送本地推送通知 - 客戶端實現是什麼樣的?

雲代碼:

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

如何能在Android客戶端正確處理這些密鑰和本地化的推動?我必須手動對Parse廣播接收器進行子類化嗎?

回答

1

是的,你必須繼承解析廣播接收機

首先,在您的清單

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

然後創建一個子類ParsePushBroadcastReceiver聲明一個接收器和覆蓋的onReceive方法。

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(); 
    } 
    } 
} 
+0

還有更多的工作。我有一個小時左右的時間,我必須重寫'getNotification'方法 - 這很煩人,因爲它構建通知而不是將它留在Builder中。所以我不能修改它返回的Notification對象上的'alert'文本。嗯。我可能不得不復制整個該死的方法,並在那裏進行警報定位。爲什麼Parse使這個如此複雜? – Aphex

+0

順便說一下,正確的重寫方法是'onPushReceive',而不是'onReceive' - 但是感謝我指出了正確的方向。 – Aphex

+0

當然,我不知道爲什麼解析這麼複雜,我用GCM做了幾次,客戶端部分變得更容易了 – wnieves19