1
我的工作中,我想每星期做上週五通知的應用程序,我已經試過這個代碼,但它使每一天通知如何每週都會製作警報通知在剛週五在Android的
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_WEEK,6);
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
String h = String.valueOf(hourOfDay);
String m = String.valueOf(minute);
Intent intent = new Intent(getApplicationContext(), notification.class);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 7*AlarmManager.INTERVAL_DAY, pendingIntent);
Toast.makeText(Settings.this, h+ " : " + m , Toast.LENGTH_SHORT).show();
Notification.class
public class notification extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
PendingIntent pendingIntent=PendingIntent.getActivity(context,0,new Intent(context,The_main.class),0);
NotificationCompat.Builder builder=new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.awq)
.setContentTitle("remainder")
.setContentText(" time to read");
builder.setContentIntent(pendingIntent);
builder.setDefaults(NotificationCompat.DEFAULT_SOUND);
builder.setAutoCancel(true);
NotificationManager notificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(1);
notificationManager.notify(1,builder.build());
}}
它在每天工作的相同問題 – abdelrhman
發佈包括Notification.class的完整代碼 – Pehlaj