버튼 클릭으로 알람 관리자를 사용하여 서비스를 시작합니다. 그것은 또한 일하고있다. 나는 이렇게했습니다 :브로드 캐스트 리시버를 통한 서비스 자동 시작
Intent scheduleSMS = new Intent(SMSProjectDatabase.this,SendSMS.class);
PendingIntent pendingIntent = PendingIntent.getService(SMSProjectDatabase.this,0, scheduleSMS,0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND,(int)GeneralUtil.calculateTimeDifference(getApplicationContext()));
Log.i("SMS is scheduled after ",""+GeneralUtil.calculateTimeDifference(getApplicationContext()));
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
여기서 SendSMS는 알람 관리자에 의해 시작될 서비스입니다. 하지만 이것은 내 코드에서 서비스를 시작하는 방법이 아닙니다. AlarmManager를 사용하여 Broadcastreceiver에 대한 브로드 캐스트를 트리거하려고합니다. 그러면 Broadcastreceiver가 나를 위해 서비스를 시작합니다.
내 방송 수신기
공용 클래스 MyReceiver가 {
@Override
public void onReceive(Context context, Intent intent) {
//here i want to start the service through the alarm manager
}
}
그러나 브로드 캐스트 리시버를 확장입니다 내가 donno 내가 나를 해결하기에 적합한 솔루션을 제공 this.Please 어떻게해야하고 어떻게 이 problelm.