동시에 여러개의 알람을 설정해서 사용하고 싶습니다.
그런데 여러개의 알람을 등록하면 마지막의 알람만 적용이되네요..
소스코드는 다음과 같습니다.
public void Alarm1Day()
{
if(Def.m_b1day == 0)
{
Alarm1(20);
Def.m_b1day = 1;
}
}
public void Alarm3Day()
{
if(Def.m_b3day == 0)
{
Alarm3(40);
Def.m_b3day = 1;
}
}
로 알람 시간을 설정했습니다.
public void Alarm1(int time)
{
Def.am1 = (AlarmManager)app.getSystemService(Context.ALARM_SERVICE);
Intent intent;
intent = new Intent( app.context_ , C22_AlarmReceiver.class );
Def.sender = PendingIntent.getBroadcast( app.context_ , 0 , intent , 0 );
// 알람 시간
Calendar calendar1 = Calendar.getInstance();
calendar1.setTimeInMillis( System.currentTimeMillis() );
calendar1.add( Calendar.SECOND , time );
Def.am1.set( AlarmManager.RTC , calendar1.getTimeInMillis() , Def.sender );
}
public static void Alarm3(int time)
{
Def.am3 = (AlarmManager)app.getSystemService(Context.ALARM_SERVICE);
Intent intent;
intent = new Intent( app.context_ , C22_AlarmReceiver.class );
Def.sender3 = PendingIntent.getBroadcast( app.context_ , 0 , intent , 0 );
// 알람 시간
Calendar calendar3 = Calendar.getInstance();
calendar3.setTimeInMillis( System.currentTimeMillis() );
calendar3.add( Calendar.SECOND , time );
// 알람 등록
Def.am3.set( AlarmManager.RTC , calendar3.getTimeInMillis() , Def.sender3 );
}
이런식으로 2개의 알람이 울리도록 설정했고요
public class C22_AlarmReceiver extends BroadcastReceiver {
private static final String TAG = "OX2알람";
@Override
public void onReceive( Context context , Intent intent )
{
// 진동
Vibrator mVib;
mVib = (Vibrator)context.getSystemService( Context.VIBRATOR_SERVICE );
// 몇초동안 1000이 1초
mVib.vibrate( 1000 );
// 어플이 실행되어 있지 않을 경우
if(Def.m_b1day == 0)
{
// 알림 통지
// NotificationManager 를 확인하세요
NotificationManager mNotiManager1 = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification noti1 = new Notification(R.drawable.icon,"서바이벌OX2",System.currentTimeMillis());
noti1.defaults |= (Notification.DEFAULT_ALL);
noti1.flags |= Notification.FLAG_AUTO_CANCEL;
// Intent 부분을 참조하세요
Intent inten = new Intent( context , LocalPushDialogActivity.class);
inten.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent content = PendingIntent.getActivity(context, 0, inten, 0);
noti1.setLatestEventInfo(context, "11111.", intent.getExtras().getString("msg"), content);
mNotiManager1.notify((int)System.currentTimeMillis(),noti1);
Def.m_b1day = 1;
}
else if(Def.m_b3day == 0)
{
// 알림 통지
// NotificationManager 를 확인하세요
NotificationManager mNotiManager3 = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification noti3 = new Notification(R.drawable.icon,"서바이벌OX2",System.currentTimeMillis());
noti3.defaults |= (Notification.DEFAULT_ALL);
noti3.flags |= Notification.FLAG_AUTO_CANCEL;
// Intent 부분을 참조하세요
Intent inten = new Intent( context , LocalPushDialogActivity.class);
inten.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent content = PendingIntent.getActivity(context, 0, inten, 0);
noti3.setLatestEventInfo(context, "2222222", intent.getExtras().getString("msg"), content);
mNotiManager3.notify((int)System.currentTimeMillis(),noti3);
Def.m_b3day = 1;
}
}
위와같이 알람이 오면 BroadcastReceiver 가 설정되도록 해놨습니다.
문제는 2개가 각자 개별적으로 동작하지많고 마지막 Alarm3 알람만 울립니다.
왜그런지 모르겠네요 ㅠ
도와주세요 ㅜ
L 감사합니다 되네요 ㅠ
한가지만 더 질문해도 될까요?
PendingIntent sender = PendingIntent.getBroadcast( app.context_ , SenderIndex , intent , 0 );
이런식으로 SenderIndex 값을 넣어서 전달했습니다.
그러면 BroadcastReceiver에서 SenderIndex 값에 따라서 다르게 처리를 해주고 싶은데
BroadcastReceiver에서 SenderIndex 을 어떻게 받나요? Intent로 전달하나요?
어플이 종료되있는데 Intent로 값을 전달하면 안될꺼같은데... 답변좀 부탁드릴게요~




PendingIntent.getBroadcast( app.context_ , 0 , intent , 0 ); 에서
아마 두 번째 값이 알람을 구분하는 걸로 알고 있습니다.
그것만 바꿔주면 될거 같네요