【发布时间】:2015-05-02 00:59:19
【问题描述】:
这就是我的设置的样子。
LunchActivity 有代码:
Parse.initialize(this, "MY_APP_ID", "MY_APP_KEY");
PushService.subscribe(this, "MyCity", HomeActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
HomeActivity 类是一个简单的活动类,它默认打开一个简单的屏幕。我还写了一个自定义接收器。
public class CityPushReceiver extends BroadcastReceiver {
private static final String TAG = "CityPushReceiver";
@Override
public void onReceive(Context context, Intent intent) {
try {
JSONObject json = new JSONObject(intent.getExtras().getString(
"com.parse.Data"));
Integer event_id = Integer.parseInt((String) json.get("event_id"));
Intent eventIntent = new Intent(context, EventResult.class);
eventIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
eventIntent.putExtra("event_id", event_id);
context.getApplicationContext().startActivity(eventIntent);
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}
}
清单文件有条目:
<receiver
android:name="com.myapp.CityPushReceiver"
android:exported="false" >
<intent-filter>
<action android:name="com.myapp.CITY_NOTIFICATION" />
</intent-filter>
</receiver>
我使用 Python 代码推送通知:
import json,httplib
connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()
connection.request('POST', '/1/push', json.dumps({
"channels": [
"MyCity"
],
"data": {
"action": "com.myapp.CITY_NOTIFICATION",
"alert": "New Event Notification",
"event_id": "425"
}
}), {
"X-Parse-Application-Id": "APP_ID",
"X-Parse-REST-API-Key": "API_KEY",
"Content-Type": "application/json"
})
result = json.loads(connection.getresponse().read())
print result
此设置未按预期工作。我确实在我的设备上收到了通知(我正在使用 AVD 进行测试)。但即使我没有点击托盘中的通知,它也会打开预期的EventResult 活动。即使我在设备主屏幕上并且应用程序仅在后台运行,也会发生这种情况。当我点击托盘中的通知时,它会打开定义为默认类的HomeActivity 类。
仅当我单击托盘中的通知时,预期的行为是打开EventResult。你们能告诉我需要改变什么吗?
【问题讨论】:
标签: android push-notification parse-platform