[英]display notification in specific time of day in android
我是android新手,有人可以在一天的特定时间向我显示详细代码以使应用显示通知吗?
如果详细显示代码,将会更好。
我只知道使用本地通知。
code is here.
很长时间= Calendar.getInstance()。getTimeInMillis(); 当+ = 10000时;
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),1,intent,PendingIntent.FLAG_UPDATE_CURRENT);
long[] pattern = {500,500};
NotificationCompat.Builder notification =
(NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification1)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setContentIntent(pendingIntent)
.setLights(Color.BLUE, 500, 500)
.setAutoCancel(true)
.setVibrate(pattern)
.setDefaults(Notification.DEFAULT_SOUND);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId允许您稍后更新通知。 mNotificationManager.notify(1,notification.build());
看看AlarmManager https://developer.android.com/reference/android/app/AlarmManager.html
AlarmManager允许您安排应用程序在将来的某个时间运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.