我正在尝试使接收器从Parse.com提供的推送通知中提取文本,我收到通知但看起来我的BroadcastReceiver没有被调用,因为Log.d没有记录< / p>
我的MainActivity.java onCreate()
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.initialize(this, "-", "-"); //removed keys for question
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseAnalytics.trackAppOpened(getIntent());
}
我的Manifest.xml接收器
<service android:name="com.parse.PushService" />
<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.example.parsepushnotificationreceiver.MyCustomReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.example.parsepushnotificationreceiver.UPDATE_STATUS" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.parsepushnotificationreceiver" />
</intent-filter>
</receiver>
我的BroadcastReceiver类
@Override
public void onReceive(Context context, Intent intent) {
try {
String action = intent.getAction();
String channel = intent.getExtras().getString("com.parse.Channel");
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());
}
}
}
我的包裹是
package com.example.parsepushnotificationreceiver;
谢谢,
解决方案:
让它工作,这个想法是在json对象中自我感知,模板{“action”:“com.example.parsepushnotificationreceiver.UPDATE_STATUS”, “名字”:“Vaughn”, “newsItem”:“男人咬狗”}
答案 0 :(得分:0)
解决方案:
让它工作,这个想法是在json对象中自我感知,模板{“action”:“com.example.parsepushnotificationreceiver.UPDATE_STATUS”,“name”:“Vaughn”,“newsItem”:“man bites狗“}