이 질문을 여러 번 물어보십시오. stackoverflow
그러나 많은 사람들이 해결하기 위해 고심 중입니다.Android AlarmManager.setExactAndAllowWhileIdle() 및 WakefulBroadcastReceiver 새롭게 제조 된 저가 기기에서 작동하지 않음
내 안드로이드 앱에서 30 분마다 장치를 켜고 현재 위치를 가져와 서버로 보내야합니다. 이를 위해 AlarmManager
을 setExactAndAllowWhileIdle()
방법과 WakefulBroadcastReceiver
과 함께 사용했습니다. 삼성, LG (넥서스), 소니, 파나소닉, 레노보, 모토로라, 마이크로 맥스 등과 같은 거의 모든 표준/인기 장치에서 작동합니다. 그러나 일부 다른 장치는 주로 중국 장치를 지원하지 않거나 장치를 깨울 수 없습니다 doze 모드에서 setExactAndAllowWhileIdle()
. 나는 alarm manager가 특정 간격으로 깨어나지 못하게하는 leeco letV (Android OS 6.1)
장치에서 그것을 테스트했다.
내 코드 부분 나는 아래에 언급 한 :
UserTrackingReceiverIntentService.java
public class UserTrackingReceiverIntentService extends IntentService {
public static final String TAG = "UserTrackingReceiverIntentService";
Context context;
public UserTrackingReceiverIntentService() {
super("UserTrackingReceiverIntentService");
}
@TargetApi(Build.VERSION_CODES.M)
@Override
protected void onHandleIntent(Intent intent) {
this.context = this;
if (!Util.isMyServiceRunning(LocationService.class, context)) {
context.startService(new Intent(context, LocationService.class));
}
Calendar calendar = Calendar.getInstance();
//********************************** SETTING NEXT ALARM *********************************************
Intent intentWakeFullBroacastReceiver = new Intent(context, SimpleWakefulReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(context, 1001, intentWakeFullBroacastReceiver, 0);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(context.ALARM_SERVICE);
if (calendar.get(Calendar.MINUTE) >= 0 && calendar.get(Calendar.MINUTE) < 30) {
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY));
calendar.set(Calendar.MINUTE, 30);
calendar.set(Calendar.SECOND, 0);
} else if (calendar.get(Calendar.MINUTE) >= 30) {
if (calendar.get(Calendar.HOUR_OF_DAY) == 23) {
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.add(Calendar.DAY_OF_MONTH, 1);
} else {
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) + 1);
}
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
} else {
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY));
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
}
//MARSHMALLOW OR ABOVE
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), sender);
}
//LOLLIPOP 21 OR ABOVE
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AlarmManager.AlarmClockInfo alarmClockInfo = new AlarmManager.AlarmClockInfo(calendar.getTimeInMillis(), sender);
alarmManager.setAlarmClock(alarmClockInfo, sender);
}
//KITKAT 19 OR ABOVE
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), sender);
}
//FOR BELOW KITKAT ALL DEVICES
else {
alarmManager.set(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), sender);
}
Util.registerHeartbeatReceiver(context);
SimpleWakefulReceiver.completeWakefulIntent(intent);
}
}
때마다 서비스 설정 다음 알람보다 30 분 후 호출하면. 내가 설정> 배터리> 정렬 웨이크 업> 장애인 모두 옵션처럼 leeco letV
장치에서 일부 설정을 변경함에 따라
public class SimpleWakefulReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// This is the Intent to deliver to our service.
Calendar calendar = Calendar.getInstance();
Intent service = new Intent(context, UserTrackingReceiverIntentService.class);
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String DateTime = sdf.format(date);
DateTime = Util.locatToUTC(DateTime);
service.putExtra("date", String.valueOf(DateTime));
String latitude = Util.ReadSharePrefrence(context, "track_lat");
String longitude = Util.ReadSharePrefrence(context, "track_lng");
service.putExtra("lat", latitude);
service.putExtra("lon", longitude);
Log.i("SimpleWakefulReceiver", "Starting service @ " + calendar.get(Calendar.HOUR_OF_DAY) + " : " + calendar.get(Calendar.MINUTE) + " : " + calendar.get(Calendar.SECOND));
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, service);
}
}
. 배터리를 사용하도록 설정하면 앱에서 강제 깨우기 기능을 무시할 수 있습니다.
내 질문 :
는 장치 같은 종류에 무슨 일이? 왜 그들은 특정 시간 간격으로 경보를 발사하지 못하게합니까?
Gionee와 같은 기기에서 2-3 분 후 알람이 작동하는 이유는 무엇입니까?
android.net.conn.CONNECTIVITY_CHANGE
네트워크 연결이 바뀌면 수신 대기 브로드 캐스팅 수신기 ..... Gionee s plus와 같은 일부 장치에서 작동하지 않을 때 어떻게해야합니까?다양한 제조업체의 배터리 최적화 설정에는 여러 가지 변형이 있습니다. 다음은이 솔루션의 경우 앱의 백그라운드 서비스에 해를 끼칠 수 있습니까?
당신이 여기 http://stackoverflow.com/q/41032943/6852390 내 질문에 대해 살펴 수 ... 사용자가 응용 프로그램을 종료 할 때마다 샤오 미의 펌웨어가 주요 프로세스를 종료 것으로 보인다. .. 도와 줄 수있는 경우 –
예를 들어 화웨이 기기의 경우 자동 시작을 사용하도록 설정해야합니다. 그렇지 않으면 브로드 캐스트를 전송할 수 없습니다. HuaweiAscend Mate 7에는 모든 응용 프로그램이 나열된 Auto Start 옵션이있는 TelephonyManager가 있습니다. 테스트를 거친 일부 기기에는 유사한 관리자가있을 수도 있습니다. – Opiatefuchs
@himCream 현재이 lib https://github.com/evernote/android-job에서 확인 중입니다. 어떻게 든 도움이 되길 바랍니다 !! 볼 수 있습니다. – MKJParekh