Android wifi background check

I started about a month or two, and I need to develop an internal hosting system based on Wifi fingerprint. I need an application that periodically scans the Wi-Fi AP and sends the result data to the server.

So far, I have created an application that allows you to scan a Wi-Fi AP and get results when it detects different connections. I am doing this in the main action using a broadcast receiver. The application can also send data to the server.

Now I want to transfer this process to a batch process in the background, even when the smartphone is in sleep mode.

I already read several topics on how to do this, but none of them was clear. My question is the best way to do this? Using a service / IntentService with a timer / timer?

Thank.

Edit: Thank you! AlarmManager and services are working fine!

+4
source share
2 answers

I think that AlarmManagersuits your needs, use setRepeatingto set something, to repeat every time X

Schedule a repeating signal. Note: for synchronization operations (ticks, timeouts, etc.), it is easier and more efficient to use Handler. If an alarm is already set for the same IntentSender, it will be canceled first.

set (int, long, PendingIntent), , , . , (PendingIntent). , , .

(, , _WAKEUP ), . ; . , , 7:45 8:45, , , 9:00.

, , , , .

: API 19 . , , , . , targetSdkVersion , API 19, , , .

ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC, RTC_WAKEUP.

triggerAtMillis , , ( ).

intervalMillis .

. , , ; IntentSender.getBroadcast().

: API 19 . , , , . , targetSdkVersion , API 19, , , .

, , .


setInexactRepeating

, ; , , , . , , setRepeating (int, long, long, PendingIntent), , , .

, . , , . , ; . setWindow (int, long, long, PendingIntent) setExact (int, long, PendingIntent).

API 19 . API 3, , , Android.

ELAPSED_REALTIME, ELAPSED_REALTIME_WAKEUP, RTC, RTC_WAKEUP.

triggerAtMillis , , ( ). : , .

intervalMillis .

API 19, INTERVAL_FIFTEEN_MINUTES, INTERVAL_HALF_HOUR, INTERVAL_HOUR, INTERVAL_HALF_DAY INTERVAL_DAY, , . , setRepeating (int, long, long, PendingIntent). API 19, . ; IntentSender.getBroadcast().

, X , , Wifi Lock, RTC_WAKEUP AlarmManager.

RTC_WAKEUP: System.currentTimeMillis() ( UTC), , .

+3

Activity to Service. AlarmManager. , . , .

: cpu lock wifi lock.

EDIT2: RTC_WAKEUP, , .

0

Source: https://habr.com/ru/post/1534653/


All Articles