Android:如何使用Pending Intent点击收到的推送通知,将后台活动启动到前台

时间:2013-08-27 13:03:14

标签: android push-notification android-pendingintent pushwoosh

我在收到推送通知后正在使用以下代码。如果我的应用程序在前台,这段代码可以正常工作。但是如果应用程序处于后台,则在单击推送通知后,“活动”不会调用。

任何想法,可能是什么问题。请告诉我。

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();
        }       
    }

0 个答案:

没有答案