나는 특별한 시간 동안 푸시 알림을 사용하려고합니다. 이 코드를 사용하고 있습니다.알람 관리자를 사용하여 특정 시간 동안 Android 푸시 알림
이 내 AlarmReceiver 클래스입니다 :
public class AlarmReceiver extends BroadcastReceiver {
private static int NOTIFICATION_ID = 1;
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager manger = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.arrrow_icon,
"test", System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(context,
NOTIFICATION_ID, new Intent(context, AlarmReceiver.class),0);
Bundle extras = intent.getExtras();
String title = extras.getString("title");
String note = extras.getString("note");
notification.setLatestEventInfo(context, note, title, contentIntent);
notification.flags = Notification.FLAG_INSISTENT;
notification.defaults |= Notification.DEFAULT_SOUND;
manger.notify(NOTIFICATION_ID++, notification);
}
};
그리고이 부분의 내 주요 클래스;
의도 alarmintent = 새로운 텐트 (getApplicationContext() AlarmReceiver.class); alarmintent.putExtra ("title", "test"); alarmintent.putExtra ("note", "test message"); PendingIntent 보낸 사람 = PendingIntent .getBroadcast (getApplicationContext(), 1, alarmintent, ) PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA); 나는 가까운 알림 작동하지 않는 강제 때
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
내 응용 프로그램이 다시 작동하면
알림이 correctly.but 노력하고 밀어 넣습니다. 도와 주셔서 감사합니다.
답장을 보내 주셔서 감사합니다.) 이것은 같은 결과입니다. 그것은 작동하지만, 응용 프로그램 메뉴에서 응용 프로그램을 강제 종료하면 알림이 작동하지 않습니다. – skhizein
ok이 코드를 사용하려고 시도했습니다. –