Android:如何使用挂起的意图在收到推送通知后点击前台启动后台活动
我正在使用以下代码,我希望在收到推送通知后运行这些代码。如果我的应用程序在前台,那么这段代码可以正常工作。但如果应用程序位于后台,则在单击推送通知后,不会调用该活动 有什么想法,有什么问题吗。请让我知道Android:如何使用挂起的意图在收到推送通知后点击前台启动后台活动,android,push-notification,android-pendingintent,pushwoosh,Android,Push Notification,Android Pendingintent,Pushwoosh,我正在使用以下代码,我希望在收到推送通知后运行这些代码。如果我的应用程序在前台,那么这段代码可以正常工作。但如果应用程序位于后台,则在单击推送通知后,不会调用该活动 有什么想法,有什么问题吗。请让我知道 public void doOnMessageReceive(String message) { try { JSONObject response = new JSONObject(message); String
public void doOnMessageReceive(String message)
{
try {
JSONObject response = new JSONObject(message);
String title = response.getString("title");
Logger.i("title","title :::"+title);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "New notification Pending";
long time = System.currentTimeMillis();
Notification notification = new Notification(icon,tickerText,time);
notification.flags = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND;
//| Notification.DEFAULT_VIBRATE |Notification.FLAG_FOREGROUND_SERVICE
//| Notification.FLAG_HIGH_PRIORITY |Notification.FLAG_ONGOING_EVENT;
CharSequence contentTitle = "Notifications";
CharSequence contentText = title;
Intent notificationIntent = new Intent(this, DetailActivity.class);
notificationIntent.putExtra(Constants.SELECTED_CATEGORY_KEY, "http://feeds.bbci.co.uk/news/rss.xml");
notificationIntent.putExtra("guid", title);
notificationIntent.putExtra(Constants.DISPLAY_ALL_CAT_KEY, true);
notificationIntent.putExtra(Constants.PARSED_RSS_DATA, RSSDataSingleton.getInstance().getRssDataHM());
notificationIntent.putExtra(Constants.MAPPED_METADATA_RSS_DATA, RSSDataSingleton.getInstance().getMappedNewsHM());
PendingIntent contentIntent = PendingIntent.getActivity(this, 99,
notificationIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);
mNotificationManager.notify(1, notification);
} catch (JSONException e) {
e.printStackTrace();
}
}
很奇怪。它应该像预期的那样工作。再次验证,如果没有,则检查Intent.Flags和pendingent.Flags的各种组合。感谢您的回复。但我已经尝试了所有这些组合的意图以及悬挂旗帜。但它似乎没有什么用处。经过进一步调查,发现如果应用程序处于前台或后台模式,则会调用广播接收器的onReceive(),并按预期运行。但是如果应用程序停止,则不会调用onReceive()。在这种情况下,它将查找要启动的活动,该活动的packagename.MESSAGE操作定义为清单中定义的意图过滤器。但我还需要向发射活动发送数据,目前发射活动似乎不起作用。如果有人知道如何将数据传递给从清单开始的活动?请评论。