如果有其他通知,我的第一个推送通知不起作用

时间:2014-06-25 06:30:01

标签: android notifications push-notification

我在Android推送通知中遇到了一个问题,正如标题所示,如果有其他通知,我的第一个推送通知无效

这是我的代码

MyNotification.Java的

public class MyNotifications {

public static NotificationManager mNotificationManager;
private Context _context;

public MyNotifications(Context context) {
    _context = context;
}

public void SetNotification(int drawable, String sender, String msg,
        String story_ID, Class<?> cls) {
    mNotificationManager = (NotificationManager) _context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    final Notification notifyDetails = new Notification(drawable, sender
            + ":" + msg, System.currentTimeMillis());
    notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL;
    long[] vibrate = { 100, 100, 200, 300 };
    notifyDetails.vibrate = vibrate;
    notifyDetails.ledARGB = 0xff00ff00;
    notifyDetails.ledOnMS = 300;
    notifyDetails.ledOffMS = 1000;
    notifyDetails.defaults |= Notification.DEFAULT_SOUND;
    // notifyDetails.number=4;
    notifyDetails.defaults = Notification.DEFAULT_ALL;
    Context context = _context;
    CharSequence contentTitle = sender;
    CharSequence contentText = msg;
    Intent notifyIntent = new Intent(context, cls);
    Bundle bundle = new Bundle();
    // bundle.putBoolean(AppConfig.IS_NOTIFICATION, true);
    notifyIntent.putExtras(bundle);
    notifyIntent.putExtra("NEWS_SECTION", "PUSH_NOTIFICATION");
    notifyIntent.putExtra("STORY_ID", story_ID);
    PendingIntent intent = PendingIntent.getActivity(_context, 0,
            notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
    notifyDetails.setLatestEventInfo(context, contentTitle, contentText,
            intent);
    mNotificationManager.notify(Integer.parseInt(story_ID), notifyDetails);
}
}

我这样称呼

MyNotifications notifications_Ahmul_Akhbar = new MyNotifications(
                            getApplicationContext());
                    notifications_Ahmul_Akhbar.SetNotification(
                            R.drawable.ic_launcher, "الفرات نيوز",
                            story_title, story_id, Articles.class);

问题在我的下图中描述 enter image description here

2 个答案:

答案 0 :(得分:0)

尝试,这将有效...

更改此

PendingIntent intent = PendingIntent.getActivity(_context, 0,
            notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);

到这个

notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent intent = PendingIntent.getActivity(context, 0,
                notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);

答案 1 :(得分:0)

请尝试这种方式,希望这有助于您解决问题。

int count=1;

PendingIntent intent = PendingIntent.getActivity(_context,(int) (Math.random() * 100),        notifyIntent, android.content.Intent.FLAG_UPDATE_CURRENT);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText,intent);
mNotificationManager.notify(count, notifyDetails);

count = count + 1;