0

How do I sent the notification only once if something happens? I got this statement:

if (diffDays <= 0 && diffHours <= 0 && diffMinutes <= 0) {

    activity.sendNotificationIfTimeEnd01();
    Log.d("MyApp", "I am here");
}

and this:

public void sendNotificationIfTimeEnd01() {
    Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("https://www.google.de/?gws_rd=ssl"));
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.ic_stat_notification);
    builder.setContentIntent(pendingIntent);
    builder.setAutoCancel(true);
    builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    builder.setContentTitle("String one");
    builder.setContentText("bla");
    builder.setSubText("blabla");
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
    try {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
        r.play();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

I do get the notification if the statement is right, but if I close the app and start it I get the notification again.(Statement is still right);

1 Answers1

0

Try using SharedPreferences as bleeding182 adviced you. This is a good answer on how to do that: How to use SharedPreferences in Android to store, fetch and edit values

Community
  • 1
  • 1
DH28
  • 553
  • 3
  • 16