※ Android 작업시 알람 등록에 대해 문제를 겪는 경우가 있다.
1. AlarmManger 알람이 울리지 않는경우
해결방법
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//API 19 이상 API 23미만
am.setExact(AlarmManager.RTC_WAKEUP, curTime, sender);
} else {
//API 19미만
am.set(AlarmManager.RTC_WAKEUP, curTime, sender);
}
} else {
//API 23 이상
am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, curTime, sender);
}
- 안드로이드 버전에 따라 알람이 울리는 방식이 다른것 같다..
2. AlarmManager 다수의 알람 등록
해결방법
Intent intent = new Intent(act, 리시버.class);
intent.putExtra("type",type);
intent.setAction("timer");
PendingIntent sender = PendingIntent.getBroadcast(getApplicationContext(), HoUtils.createID(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
여기서중요한
<HoUtils.createID()>
- 이 함수는 PendingIntent를 사용하여 데이터를 넘길때, 새로운 데이터를 등록해주기 위해사용한다.
처음에 1이라는 int형 변수를 사용했다면 그 다음데이터는 2, 3, 4... 이런식으로 나가면 되고 중복되지 않으면 된다.
AlarmManager를 이렇게 사용하게 되면, 다중으로 알람을 등록할수 있다.
- 다른방법이 있다면 댓글로 공유해주세요~!
※파트너스 활동을 통해 일정액의 수수료를 제공받을 수 있음※
'IT개발일지 > Android' 카테고리의 다른 글
[Android] 초간단 카카오 채널연동하기 (0) | 2019.11.28 |
---|---|
[Android]Must be called from main thread of fragment host |에러 (0) | 2019.11.27 |
[Android] calling button effect library (ripple) (0) | 2019.11.11 |
[Android] 안드로이드 mic 사용하기(채팅 음성메세지) (0) | 2019.09.30 |
[Android] Android Uri 실제 경로 받아오기 (0) | 2019.08.26 |