I rendered the function:

public boolean hasInternetConnection() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (cm == null) { return false; } NetworkInfo[] netInfo = cm.getAllNetworkInfo(); if (netInfo == null) { return false; } for (NetworkInfo ni: netInfo) { if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.isConnected()) { Log.d(this.toString(), "Wifi conncetion found"); return true; } if (ni.getTypeName().equalsIgnoreCase("MOBILE")) if (ni.isConnected()) { Log.d(this.toString(), "Mobile connection found"); return true; } } return false; } 

- in a separate java file, how can I use it in other java files now?

  • @dayMe, To format the code, select it with the mouse and click on the button 101010 of the editor. - ReinRaus

2 answers 2

In Java, this is done using import .

    Just because the method can not stand. It is necessary to wrap it in class.