<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); int connectNum = 0; ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); for (Network network : connMgr.getAllNetworks()) { NetworkCapabilities networkInfo = connMgr.getNetworkCapabilities(network); if (networkInfo.hasTransport (NetworkCapabilities.TRANSPORT_ETHERNET) == true ) { connectNum++; } } Log.d("haha check connect", "num="+connectNum); } }
沒有留言:
張貼留言