4

I have this application that needs to pull data from a server every 30 minutes, after a lot of search I reached this solution: 1- using AlarmManager to notify the application each 30 minutes instead of keeping the service running in the background. 2- using wakelocks with PARTIAL_WAKE_LOCK

My only problem is that Wifi is off at sleep time.

How can I request that I need an internet connection when my alarm is triggered??

4

3 回答 3

0

前段时间我遇到了完全相同的问题。不幸的是我没有成功。我尝试了以下方法:

    WifiManager wman = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);

    try {
        wman.reconnect();
    } catch (Exception e) {
        e.printStackTrace();
        return false;

    }

也许您可以使用WifiManager并找到我没有找到的方法。哦,是的,别忘了在清单中设置 WIFI 权限。

干杯卢卡斯

于 2012-02-04T10:52:50.780 回答
0
  1. 警报管理器通过接收器唤醒您的唤醒意图服务
  2. 唤醒意图服务获取 wifi 锁
  3. 服务注册连接和调用的接收器reconnect()reassociate()以及所需的任何内容(这可能是特定于设备的)
  4. 服务等待闩锁
  5. 连接wifi时接收器唤醒服务

骨架代码:https ://stackoverflow.com/a/19968708/281545

于 2013-11-14T03:11:04.177 回答
0

Note for Android 6 (API level 23) and above. Since Google introduced Optimizing for Doze and App Standby, things are getting more complicated. Look here - https://developer.android.com/training/monitoring-device-state/doze-standby.html Now it is much harder to force access to the network at a specific time.

于 2017-04-21T06:29:35.310 回答