I want to make sure the device is connected to the Internet.
There is a method called isAvailable()
in the NetworkInfo
class, and I think you can use this.
NetworkInfo ni = new NetworkInfo();
if (!ni.isAvailable()) {
// // do something
}
The constructor NetworkInfo is not visible.
I got this error. Is there any other way to get NetworkInfo?
android internet-connection android-internet
connectivitymanager of
getactivenetworkinfo (),
, if the Internet is connected networkinfo
the return or null back.
You can check if the Internet is connected with this return value.
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
Please refer to the sauce
Oh! And
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
You must go to the Android manifest file and insert the above code.
584 PHP ssh2_scp_send fails to send files as intended
576 Who developed the "avformat-59.dll" that comes with FFmpeg?
922 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.