[英]How can I check if wifi is receiving data on android?
So I've gone through a lot of trouble recently trying to figure out how to check if wifi connection is actually working on Android. 因此,最近我在尝试找出如何检查wifi连接在Android上是否真的工作时遇到了很多麻烦。 I'm aware there are a lot of threads with similar matter around the community, but those mostly approach the issue from ConnectivityManager which seemingly is only able to check if there is a WiFi connection stablished and that is not enough.
我知道社区中有很多具有类似问题的线程,但是大多数线程都从ConnectivityManager处理问题,看似只能检查是否建立了WiFi连接,这还不够。
I've also seen people suggesting ping/HTTP checks but I would like to know if there is a way around those methods since that would use any available data. 我也见过有人建议ping / HTTP检查,但我想知道是否有办法解决这些方法,因为那会使用任何可用数据。
I intend to run the solution in a service that periodically checks if connection is available and phone is online, although I'm not quite sure if that's a viable way of accomplishing my goals. 我打算在一项服务中运行该解决方案,该服务会定期检查连接是否可用以及电话是否在线,尽管我不确定这是否是实现目标的可行方法。
Service: 服务:
package com.mattos.murilorm.meavisaquandotiverinternet;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyService extends Service{
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this,"Service started!",Toast.LENGTH_LONG).show();
return START_STICKY;
}
@Override
public void onDestroy() {
Toast.makeText(this,"Service destroyed!",Toast.LENGTH_LONG).show();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Please help! 请帮忙!
There's no way of detecting actual connection quality without sampling some data, so if you don't want to do ping style requests you don't have a lot of options other than a simple check for whether or not you are connected to something. 如果不对某些数据进行采样,就无法检测实际的连接质量,因此,如果您不想执行ping样式请求,除了简单地检查是否已连接到某物之外,您没有太多选择。
Facebook made a pretty useful library that will: Facebook开发了一个非常有用的库,它将:
Listen to current network traffic in the app and categorize the quality of the network.
在应用程序中收听当前的网络流量,并对网络质量进行分类。
It's called network-connection-class . 这称为network-connection-class 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.