Recently, the project needs to use AlarmManager to wake up Baidu positioning when the cpu is sleeping. The following is an example of calling code:
-- Periodic broadcast locating
Public static void sendLocationBroadcastRepeat (Context ctx ){
Intent intent = new Intent (ctx, LocationBroadcast. class );
PendingIntent pendingIntent = PendingIntent. getBroadcast (ctx, 0,
Intent, 0 );
// Start time
Long firstime = SystemClock. elapsedRealtime ();
AlarmManager am = (AlarmManager) ctx
. GetSystemService (Context. ALARM_SERVICE );
Am. setRepeating (AlarmManager. ELAPSED_REALTIME_WAKEUP, firstime,
10*1000, pendingintent );
Log. I (TAG, "sendupdatebroadcastrepeat is start ");
}
Note: The 10-second loop call broadcast is set. During the running process, it is found that the broadcast is not called at the set time. I thought it was a code problem and there was no error in the code after troubleshooting. The test runs normally on the meizu 2 mobile phone (according to the settings ). Why didn't I run as set On Xiaomi's phone?
Repeated tests showed that Xiaomi mobile phones repeatedly call broadcast at intervals of 5 minutes:
Problem tracking:
- Call Xiaomi technical support by phone. The other party replies to refresh Xiaomi's latest miui (Development version). The refresh result remains the same;
- Refresh the latest stable version. The result is the same;
- ......
If you have any questions, please let us know. Thank you!
Solution:
- Set the firstime value to a value greater than or equal to 5 minutes (at present, Xiaomi miui is in this situation and we hope Xiaomi can solve this problem)