【发布时间】:2014-11-15 10:23:39
【问题描述】:
我有一些 Parse 代码可以接收推送数据并设置一个可以正常工作的通知,但问题是 onPushOpen 声明。我想在我的应用中打开一个特定的活动,但 onPushOpen 似乎永远不会被调用或只是不起作用?
这是我的代码:
public class NotificationReceiver extends ParsePushBroadcastReceiver {
private static final String TAG = "MYTAG";
@Override
public void onReceive(Context context, Intent intent) {
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Log.i(TAG, "Notification received");
Bundle extras = intent.getExtras();
String message = extras != null ? extras.getString("com.parse.Data") : "";
JSONObject jObject;
String alert = null;
String title = null;
try {
jObject = new JSONObject(message);
alert = (jObject.getString("alert"));
title = (jObject.getString("title"));
}
catch (JSONException e) {
e.printStackTrace();
}
Log.i(TAG,"alert is " + alert);
Log.i(TAG,"title is " + title);
NotificationCompat.Builder notification =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(alert)
.setContentText(title);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, notification.build());
Log.i(TAG, "Notification created");
}
@Override
protected void onPushOpen(Context context, Intent intent) {
Log.i(TAG, "Notification clicked");
Intent i = new Intent(context, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
我似乎无法弄清楚为什么 onPushOpen 没有启动我请求的活动 (MainActivity)。任何帮助将不胜感激。
【问题讨论】:
-
没有错误。推送/点击/单击通知时没有任何反应
-
你知道
onPushOpen()被调用了吗? -
我没有。据我在解析文档中发现,当您单击通知时会调用 onPushOpen。但是我没有看到我在方法开始时写的日志消息...
标签: android android-intent notifications parse-platform push-notification