[英]Android java sent notification once
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); 如果语句正确,我确实会收到通知,但是如果我关闭应用程序并启动它,则会再次收到通知。(声明仍然正确);
Try using SharedPreferences as bleeding182 adviced you. 尝试使用SharedPreferences,因为建议您不满182。 This is a good answer on how to do that: How to use SharedPreferences in Android to store, fetch and edit values
这是如何执行此操作的好答案: 如何在Android中使用SharedPreferences来存储,获取和编辑值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.