안드로이드 장치가 깨어 났을 때 계산을 시작하고 안드로이드 장치가 잠자기 상태로 설정되면 타이머를 만들고 싶습니다. 나는 아무 것도 발견하지 못했고, 잠에서 깨어서 잠을 자면 어떤 활동이 시작될 수 있었는지 .Android에서 깨우기/잠자기시 활동 시작
은 당신이 당신은 ACTION_BOOT_COMPLETED 의도를 수신 대기 브로드 캐스트 리시버를 작성해야 내 문제
안드로이드 장치가 깨어 났을 때 계산을 시작하고 안드로이드 장치가 잠자기 상태로 설정되면 타이머를 만들고 싶습니다. 나는 아무 것도 발견하지 못했고, 잠에서 깨어서 잠을 자면 어떤 활동이 시작될 수 있었는지 .Android에서 깨우기/잠자기시 활동 시작
은 당신이 당신은 ACTION_BOOT_COMPLETED 의도를 수신 대기 브로드 캐스트 리시버를 작성해야 내 문제
나는 timonvlad와 같이 BroadcastReceiver를 사용했지만 ACTION_SCREEN_ON과 ACTION_SCREEN_OFF는 XML로 호출 할 수 없어서 서비스를 만들었습니다. 서비스를 XML에 등록한 다음이 코드를 사용합니다.
public class OnOffReceiver extends Service {
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
registerReceiver(new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
//This happens when the screen is switched off
}
}, new IntentFilter(Intent.ACTION_SCREEN_OFF));
registerReceiver(new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
//This happens when the screen is turned on and screen lock deactivated
}
}, new IntentFilter(Intent.ACTION_USER_PRESENT));
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
를 도와 줄 수 있기를 바랍니다. 구현시 해당 인 텐트가 수신 된 시간 스탬프를 저장해야합니다.
그런 다음, 해당 시간 소인을 검색하는 활동을 작성하고 전화가 실행 된 시간을 계산할 수 있습니다.
AlarmManager.setRepeating(AlarmManager.RTC, time, period, pendingIntent);
:
사용 BroadcastReceiver
및 서비스
public class InternetReceiver extends BroadcastReceiver{
private boolean screenOff;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
screenOff = true;
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
screenOff = false;
}
Intent i = new Intent(context, InternetService.class);
i.putExtra("screen_state", screenOff);
context.startService(i);
}
}
장치가 깨어있을 때 해고 될 이벤트를 반복 설정 ... 같은 예를 들어 .... Screen_on를 잡을 and_off하기 그런 다음 알람을 잡아 타이머 카운터를 증가 시키면 장치가 깨어 났을 때 계산됩니다.
장치가 깨어날 때 작업을 시작하지 마십시오. 사용자는 앱의 이러한 동작에 대해 만족하지 않을 것입니다. 알림을 대신 사용하십시오.