사용자가 위치를 기록하는 알람을 추가 할 수있는 Android 응용 프로그램이 있습니다. 예를 들어, 매일 오전 8시에 나는 어디에 있는지 기록하고 싶습니다. 알람이 수신되면 사용자의 위치를 가져 와서 db에 저장하는 서비스를 시작합니다. 이 기능은 앱이 실행 중일 때 (배경 또는 전경) 잘 작동합니다.응용 프로그램이 실행 중일 때만 알람이 수신됩니다.
문제는 내가 작업 관리자로 들어가서 앱을 강제 종료하면 알람이 꺼지지 않는 것 같습니다. 이는 사용자가 휴대 전화를 재부팅하고 앱을 종료 할 수 있기 때문에 중요합니다. 이런 일이 왜
public class AlarmReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
int alarmId = bundle.getInt(Constants.ALARMID_FIELD_NAME);
Toast.makeText(context, "Alarm Running: ID = " + alarmId, Toast.LENGTH_LONG).show();
Log.d(TAG, "AlarmReceiver: onRecieve. ID = " + alarmId);
Intent serviceIntent = new Intent(context, LocationRecordingService.class);
serviceIntent.putExtra(Constants.ALARMID_FIELD_NAME, alarmId);
context.startService(serviceIntent);
}
}
어떤 생각 : 여기
private void setNewAlarm(int hour, int minute, int id) {
Intent alarmIntent = new Intent(AutoLoggerActivity.this, AlarmReciever.class);
alarmIntent.putExtra(Constants.ALARMID_FIELD_NAME, id);
PendingIntent sender = PendingIntent.getBroadcast(AutoLoggerActivity.this, id, alarmIntent, 0);
Calendar alarmCal = Calendar.getInstance();
alarmCal.set(Calendar.HOUR_OF_DAY, hour); // set user selection
alarmCal.set(Calendar.MINUTE, minute); // set user selection
alarmCal.set(Calendar.SECOND, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarmCal.getTimeInMillis(), 120000, sender);
}
브로드 캐스트 리시버입니다 : 여기
알람을 설정하는 방법은 무엇입니까?
위대한 정보 주셔서 감사합니다! 소스를 연결할 수 있습니까? –
다음은 기능이 추가 된 Android 3.1 출시 노트의 설명입니다. http://developer.android.com/about/versions/android-3.1.html#launchcontrols – Devunwired
다시 한번 감사드립니다. –