嗨,我尝试使用以下方法检查网络连接和Internet存在
check = new ConnectionDetector(getApplicationContext());
conn = check.isConnectingToInternet();
public class ConnectionDetector {
private Context _context;
public ConnectionDetector(Context context){
this._context = context;
}
/**
* Checking for all possible internet providers
* **/
/*public boolean isConnectingToInternet(){
ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null)
{
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
return true;
}
}
return false;
}*/
public boolean isConnectingToInternet(){
try{
ConnectivityManager cm …Run Code Online (Sandbox Code Playgroud) 码:
enum EBtnSts
{
static
{
ePlayBtn = new EBtnSts("ePlayBtn", 1);
EBtnSts[] arrayOfEBtnSts = new EBtnSts[0];
arrayOfEBtnSts[0] = ePlayBtn;
}
}
Run Code Online (Sandbox Code Playgroud)