当我处于暂停状态时,Wifi已断开连接

时间:2018-08-01 14:29:33

标签: java android xamarin

我需要始终启用wifi,因为我的应用程序处于活动状态。

我尝试过:

 protected override void OnResume()
    {
        base.OnResume();

        WifiManager wifiManager = (WifiManager)GetSystemService(Context.WifiService);
        WifiManager.WifiLock wifiLock = wifiManager.CreateWifiLock(Android.Net.WifiMode.FullHighPerf, "SYNCVR");
        wifiLock.Acquire();

        PowerManager pm = (PowerManager)GetSystemService(Context.PowerService);
        PowerManager.WakeLock wl = pm.NewWakeLock(WakeLockFlags.Full, "MyTag");
        wl.Acquire();



    }

  //This timer is running every 10'' when i'm on Pause
  private void Tmr_Elapsed(object sender, ElapsedEventArgs e)
    {
        ConnectivityManager connectivityManager = (ConnectivityManager)GetSystemService(Context.ConnectivityService);
        NetworkInfo activeNetworkInfo = connectivityManager.ActiveNetworkInfo;

        Write.LogFile(Convert.ToString(activeNetworkInfo));
    }

但是当我处于暂停状态时,有时会收到消息

WifiState已断开连接/已阻止

我还能尝试什么? 我不使用wifilock.release,因为我需要wifi始终在PauseMode上“打开”

0 个答案:

没有答案