Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. private void checkNetworkConnection() {
  2. ConnectivityManager connMgr =
  3. (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
  4. NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
  5.  
  6. if (activeInfo != null && activeInfo.isConnected()) {
  7.  
  8. boolean wifiConnected = activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
  9. boolean mobileConnected = activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
  10.  
  11. if(wifiConnected) {
  12. Log.i(TAG, "WIFI connected");
  13. stsRede.setText("Conectado no WiFi");
  14. } else if (mobileConnected){
  15. Log.i(TAG, "Mobile Connected");
  16. //stsRede.setText("Conectado no 3G");
  17. }
  18. } else {
  19. Log.i(TAG,"Neither Mobile nor WIFi connected.");
  20. //stsRede.setText("Sem conexão a internet");
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement