특정 시간에 매일 알림을 표시해야합니다 (예 : 4.25PM). AlarmManager
과 Notification
을 사용하고 있습니다. 응용 프로그램의 방문 페이지에 경보를 설정했습니다. 또한 BroadcastReceiver
을 구현했습니다.AlarmManager를 사용하여 특정 시간에 알림 표시
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 16);
calendar.set(Calendar.MINUTE, 25);
calendar.set(Calendar.SECOND, 0);
Intent notificationmassage = new Intent(getApplicationContext(),Notificationmassage.class);
//This is alarm manager
PendingIntent pi = PendingIntent.getService(this, 0 , notificationmassage, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pi);
이 방송 수신기
public class Notificationmassage extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
showNotification(context);
}
private void showNotification(Context context) {
Log.i("notification", "visible");
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(context, Notificationmassage.class), 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("xyz")
.setContentText("It will contain dummy content");
mBuilder.setContentIntent(contentIntent);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(true);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}
이 방법에 문제가 있습니다 무엇입니까 :
코드 알람을 설정하는 방법?
안녕을 보여주십시오. Whats the question ... 죄송합니다. 아래로 스크롤되었습니다. 문제를 일으킬 수있는 유일한 사실은 그 사람이 응용 프로그램을 열지 않으면 어떻게되는지입니다. – Pintac
안녕하세요, 특정 시간에 Android 앱을 던져 알림을 보내야합니다. 위 코드를 완료했지만 작동하지 않습니다. –
안녕하세요. 정의가 작동하지 않습니다. 방송에 들어 가지 않거나 알림을 표시하지 않습니까? – Pintac