私はこのように私のアプリケーションでローカル通知を使用しています。
showNotification(this, "Title1", "Message One", 1);
showNotification(this, "Title2", "Message Two", 2);
showNotification(this, "Title3", "Message Three", 3);
showNotification(this, "Title4", "Message Four", 4);
public static void showNotification(Context con, String title,
String message, int id) {
NotificationManager manager = (NotificationManager) con
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.ic_noti_logo,title, System.currentTimeMillis());
Intent notificationIntent = new Intent(con,Result.class);
notificationIntent.putExtra("Message", message);
notificationIntent.putExtra("NotiId", id);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pi = PendingIntent.getActivity(con, 0,
notificationIntent, PendingIntent.FLAG_ONE_SHOT);
note.setLatestEventInfo(con, title, message, pi);
note.defaults |= Notification.DEFAULT_ALL;
note.flags |= Notification.FLAG_AUTO_CANCEL;
manager.notify(id, note);
}
Resut.javaで
message = getIntent().getStringExtra("Message");
notiId = getIntent().getIntExtra("NotiId", 0);
showAlert(message,notiId);
private void showAlert(String msg, int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(msg).setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// finish();
cancelNotification(Result.this,id);
}
});
AlertDialog alert = builder.create();
alert.show();
}
public static void cancelNotification(Context con, int id) {
NotificationManager manager = (NotificationManager) con
.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(id);
}
私の問題は、通知バーに4つの通知メッセージが表示され、それらのいずれかをクリックするとResult
アクティビティにリダイレクトされますが、2回目にクリックしても効果がなかった場合にのみ発生します。私を助けてください。