小米手机后台限制App联网

最近做的app中由一个后台长连接,可能根据具体的业务需求不定时的向用户发送一下通知栏消息,最近有用户反馈没有收到通知栏消息,调试了好久也没有发现什么问题,由于反馈的多是小米手机出现的这个问题,特地从测试哪里拿来一个红米note2调试了一下,期初长连接都是正常的,但是程序退出之后,过了大概五六分钟之后长连接开始不正常,日志显示的错误时:

java.net.SocketException: recvfrom failed: ETIMEDOUT (Connection timed out)
at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:634)
at libcore.io.IoBridge.recvfrom(IoBridge.java:608)
at java.nio.SocketChannelImpl.readImpl(SocketChannelImpl.java:342)
at java.nio.SocketChannelImpl.read(SocketChannelImpl.java:304)
at org.apache.mina.transport.socket.nio.NioProcessor.read(NioProcessor.java:311)
at org.apache.mina.transport.socket.nio.NioProcessor.read(NioProcessor.java:45)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:694)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:668)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:657)
at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(AbstractPollingIoProcessor.java:67)
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1121)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: android.system.ErrnoException: recvfrom failed: ETIMEDOUT (Connection timed out)
at libcore.io.Posix.recvfromBytes(Native Method)
at libcore.io.Posix.recvfrom(Posix.java:156)
at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:245)
at libcore.io.IoBridge.recvfrom(IoBridge.java:605)
at java.nio.SocketChannelImpl.readImpl(SocketChannelImpl.java:342) 
at java.nio.SocketChannelImpl.read(SocketChannelImpl.java:304) 
at org.apache.mina.transport.socket.nio.NioProcessor.read(NioProcessor.java:311) 
at org.apache.mina.transport.socket.nio.NioProcessor.read(NioProcessor.java:45) 
at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:694) 
at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:668) 
at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:657) 
at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(AbstractPollingIoProcessor.java:67) 
at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1121) 
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at java.lang.Thread.run(Thread.java:818) 

后台经过查询发现小米手机有一个限制后台运行时联网功能:安全中心-》网络助手-》流量排行榜-》找到自己的应用:

小米手机后台限制App联网_第1张图片

小米不知道为什么将自己的应用后台联网功能关闭了,所以后台的长连接无法保持,查看了一下其他应用,微信,支付宝等都是开启的,不太熟悉小米的算法,而且没有相应的能够打开这个而设置的API,所以暂时没想出什么比较好的办法解决这个问题。

你可能感兴趣的:(小米手机后台限制App联网)