如何在非活动应用程序的ParsePushBroadcastReceiver或ParseBraodcastReceiver中接收解析通知数据?

时间:2015-07-14 20:27:06

标签: android parse-platform

清单文件

  

我包括以下接收器

<service android:name="com.parse.PushService" />
  

这是MyParseService扩展ParseBroadcastReceiver

    <receiver android:name=".MyParseReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="com.wattabyte.detectivecamparse.UPDATE_STATUS" />
        </intent-filter>
    </receiver>
    <receiver
        android:name=".DetectiveCamPushReceiver"
        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" />
            <action android:name="com.wattabyte.detectivecamparse.UPDATE_STATUS" />
        </intent-filter>
    </receiver>

MyParseReceiver类

  

此Class是ParsePushBroadcastReceiver的子类   这里尝试使用onReceivemethod获取通知

public class MyParseReceiver extends ParseBroadcastReceiver {
 @Override
public void onReceive(Context context, Intent intent) {
    try {
        if (intent == null)
        {
            Log.d(TAG, "Receiver intent null");
        }
        else
        {
            String action = intent.getAction();
            Log.d(TAG, "got action " + action );
            if (action.equals("com.wattabyte.detectivecamparse.UPDATE_STATUS"))
            {
                String channel = intent.getExtras().getString("Wattabyte");
                JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));

                Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
                Iterator itr = json.keys();
                while (itr.hasNext()) {
                    String key = (String) itr.next();

            Log.d(TAG, "..." + key + " => " + json.getString(key));
                }
            }
        }

    } catch (JSONException e) {
        Log.d(TAG, "JSONException: " + e.getMessage());
    }
}

DetectiveCamPushReceiver

  

这是ParsePushBroadcastReceiverClass   我尝试使用Push Receive和Push open

 @Override
protected void onPushOpen(Context context, Intent intent) {
    // Implement
    ParseAnalytics.trackAppOpenedInBackground(intent);
}

@Override
protected void onPushReceive(Context context, Intent intent) {
    JSONObject data = getDataFromIntent(intent);
    // Do something with the data. To create a notification do:
        Log.e("Vinay",""+data.toString());
    if (data != null){
        Log.e("MSG","Data pushed from parse");
    }


    // OPTIONAL create soundUri and set sound:


}

private JSONObject getDataFromIntent(Intent intent) {
    JSONObject data = null;
    try {
        data = new JSONObject(intent.getExtras().getString(PARSE_DATA_KEY));
    } catch (JSONException e) {
        // Json was not readable...

    }
    return data;
}
  

帮助我阅读 ParsePush 数据后台活动

     

提前致谢   任何帮助将不胜感激

0 个答案:

没有答案