小编Zen*_*mer的帖子

生成int unique id作为android通知id

当我发送多个推送通知时,我需要它们全部显示在发送时间desc的通知栏中.我知道我应该使用独特的通知 - 我试图生成随机数,但这并没有解决我的问题,因为我需要它们被订购.我试图使用AtomicInt,但仍然没有达到预期的效果.

package com.mypackage.lebadagency;
import java.util.concurrent.atomic.AtomicInteger;

import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.util.Log;



import android.widget.RemoteViews;

import com.google.android.gms.gcm.GoogleCloudMessaging;

public class GCMNotificationIntentService extends IntentService {

  private AtomicInteger c = new AtomicInteger(0);
  public int NOTIFICATION_ID = c.incrementAndGet(); 

  private NotificationManager mNotificationManager;
  NotificationCompat.Builder builder;

  public GCMNotificationIntentService() {
    super("GcmIntentService");
  }

  public static final String TAG = "GCMNotificationIntentService";

  @Override
  protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging …
Run Code Online (Sandbox Code Playgroud)

java android push-notification

51
推荐指数
6
解决办法
4万
查看次数

标签 统计

android ×1

java ×1

push-notification ×1