android.net.ConnectivityManager cm = (android.net.ConnectivityManager) this.getSystemService(android.content.Context.CONNECTIVITY_SERVICE);

android.net.NetworkInfo activeNetwork = cm.getActiveNetworkInfo();

if (activeNetwork != null) {
if (activeNetwork.getType() == android.net.ConnectivityManager.TYPE_WIFI) {
text.setText("Wifi is active");
} else if (activeNetwork.getType() == android.net.ConnectivityManager.TYPE_MOBILE) {
text.setText("mobile is active");
}
} else {
text.setText("No connection");
}



//Need permission
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />