嗨我所有的Android推送通知都运行良好。但如果我的应用只有一个通知,用户触摸它后它就会清除。但是如果有多个通知(通过使用id)只有第一个通知后触摸一些通知是仍然显示在satusbar.I使用NotificationCompat.Builder所以我需要使用.setAutoCancel(true)。 这是我的代码(请注意'collapse_key'是1到12之间的整数,它不是GCM概念中的折叠键)
@Override
protected void onMessage(Context ctx, Intent intent) {
int myId;
Log.d("Time",""+System.currentTimeMillis());
Intent intenti = new Intent(Intent.ACTION_MAIN);
intenti.putExtra("k12grade",intent.getStringExtra("k12grade"));
Log.d("NOT:","k12garde="+intent.getStringExtra("k12grade"));
intenti.setClass(this.getBaseContext(),QuizByteGradeRankersActivityPush.class);
intenti.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent sender = PendingIntent.getActivity(this.getBaseContext(), 192839, intenti, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("New Top Ranker!")
.setPriority(Notification.PRIORITY_HIGH)
.setContentText(intent.getStringExtra("message"))
.setAutoCancel(true)
.setContentIntent(sender)
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(intent.getStringExtra("message")));
myId=Integer.parseInt(intent.getStringExtra("collapse_key"));
Log.d("NOT:","collapse key="+myId);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(myId, mBuilder.build());
}