내 응용 프로그램에서 GCM 메시지가 처음 알림 바에 표시됩니다. 해당 알림을 클릭하면 GCM을 통해받은 메시지가 표시되는 응용 프로그램 활동으로 이동합니다. GCM을 읽는 경우 메시지를 보내고 알림 영역에 처음 표시되는 다른 GCM 메시지를받습니다. 새 알림을 클릭하면 애플리케이션의 의도 된 활동을 시작하고 데이터를 전달하여 자체를 파괴해야합니다. 대신 이 문제는 다음과 같습니다. 이미 GCM 메시지를 읽고 방금받은 새 알림을 클릭하면 이전 메시지와 함께 이미 실행중인 활동이 표시되고 알림도 삭제되지 않습니다.단일 장치에 여러 개의 GCM 메시지 처리
통지를 처리하는 내 코드는 다음과 같습니다
private void sendNotification(String msg) {
SharedPreferences prefs = getSharedPreferences(
DataAccessServer.PREFS_NAME, MODE_PRIVATE);
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, WarningDetails.class);
Bundle bundle = new Bundle();
bundle.putString("warning", msg);
bundle.putInt("warningId", NOTIFICATION_ID);
intent.putExtras(bundle);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.weather_alert_notification)
.setContentTitle("Weather Notification")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg);
String selectedSound = prefs.getString("selectedSound", "");
if (!selectedSound.equals("")) {
Uri alarmSound = Uri.parse(selectedSound);
mBuilder.setSound(alarmSound);
} else {
Uri alarmSound = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mBuilder.setSound(alarmSound);
}
if (prefs.getBoolean("isVibrateOn", false)) {
long[] pattern = { 500, 500, 500, 500, 500, 500, 500, 500, 500 };
mBuilder.setVibrate(pattern);
}
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
WarningDetails 활동 코드는 다음과 같습니다
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.warning_details);
warning = (TextView) findViewById(R.id.warningDetails);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String warningData = extras.getString("warning");
//if (extras.getInt("warningId") != 0) {
NotificationManager mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(1);
//}
if (warningData != null) {
warning.setText(warningData);
} else {
// Do nothing
}
} else {
// Do nothing
}
}
내가