날씨 어플을 테스트로 만들고 있는 중입니다.
TimePickerDialog로 시간을 받아서 리시버를 걸어서 액션을 실행하는데 당췌 리시버 액션을 타지 않네요.
구글링도 해보고 예제소스에서 되는 것을 똑같이 넣어서 해보아도 동작을 하지 않습니다.
노티도 안터지고요 ㅠㅠ
지금 다 되었는데 알람에서 막혀서 개삽질 중입니다. 좀 도와주세요 ㅠㅠ
알람 설정 java
// TimePicker Dialog 호출
TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Calendar cal = Calendar.getInstance();
cat = Calendar.getInstance();
mHour = hourOfDay;
mMin = minute;
cat.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH), hourOfDay, minute, 0);
updateNow();
}
};
// 알람 세팅
private void setAlarm() {
am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(getApplicationContext(), AlarmReceive.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, 0);
year = cat.get(Calendar.YEAR);
month = cat.get(Calendar.MONTH);
day = cat.get(Calendar.DAY_OF_MONTH);
hour = cat.get(Calendar.HOUR_OF_DAY);
minute = cat.get(Calendar.MINUTE);
cal.set(year, month, day, hour, minute);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pi);
}
void updateNow(){
setAlmTime.setText(String.format("%d:%d", mHour, mMin));
wdb.updateInfo("TIME", String.format("%d:%d", mHour, mMin));
setAlarm();
}
알람 리시버 액션
public class AlarmReceive extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm Received!", Toast.LENGTH_LONG).show();
NotificationManager notifier = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify = new Notification(R.drawable.ic_launcher, "text", System.currentTimeMillis());
Intent intent2 = new Intent(context, ArmisirActivity.class);
PendingIntent pender = PendingIntent.getActivity(context, 0, intent2, 0);
notify.setLatestEventInfo(context, "alimtitle", "hackjang", pender);
notify.flags |= Notification.FLAG_AUTO_CANCEL;
notify.vibrate = new long[] { 200, 200, 500, 300 };
//notify.sound=Uri.parse(R.raw.r3);
notify.number++;
notifier.notify(1, notify);
}
}
매니페스트 리시버 등록
<receiver android:name=".AlarmReceive" />
문제는 리시버 액션 자체가 동작하지 않습니다. 매니페스트가 잘못 되었나 하여 intent-filter도 걸어보고 android:process도 해보고
혹시나 시간이 잘 못 가지 않나 싶어서 로그도 찍어보았으나 정상적인 상태로 인식되고 있었습니다.
어떤 것이 문제일까요? 다 작업해놓고 이것때문에 하루를 버렸네요....
고수분들의 많은 가르침을 부탁드립니다.