Determine the network connection status and network connection

Source: Internet
Author: User

Determine the network connection status and network connection
/**
* Determine the network connection status
*/
Public static boolean isNetworkAvailable (Context context ){
ConnectivityManager cwjManager = (ConnectivityManager) context
. GetSystemService (Context. CONNECTIVITY_SERVICE );
NetworkInfo info = cwjManager. getActiveNetworkInfo ();
If (info! = Null & info. isConnected ()){
CustomizedCustomToast. makeText (mContext, "Network Available ",
Toast. LENGTH_LONG). show ();
Return true;
} Else {
CustomizedCustomToast. makeText (mContext, "Network unAvailable ",
Toast. LENGTH_LONG). show ();
Return false;
}
}
Easy language to determine whether the network is connected

Call format: <logical type> connecting to the Internet ()-Application Interface Support library-> Network Communication
English name: IsConnectToInternet
Checks whether the current network status is connected to the Internet. Success returns true; Failure returns false. If this command returns true, you must be able to access the Internet. This command is a basic command.

Operating System Requirements: Windows

Copy and paste the source code. There is no need to upload attachments for two or three sentences of code, or just repeat them by yourself. I hope you can adopt them in time. Thank you !~~

. Version 2
. Supports library eAPI

. Subroutine _ start window _ created

. If the true (reverse (whether it is connected to the Internet () 'check whether there is a network connection, the following message box is displayed, some networks skip this command. If the real command continues executing the code, the program runs normally.
Information Box ("No network connection is detected currently, please check the network and try again", 0,) 'prompt in the information box when no network exists
Terminate () 'terminate the program
. If it really ends



How can I determine whether the network is connected in easy language?

. Version 2

. Subroutine 1
. Local variable in_parameter, short Integer type

. If it is true (InternetGetConnectedState (Bureau _ parameter, 0 ))
Debug output (Bureau _ parameter)

Yes. The first parameter is in the out type, and the variable format is required,
Add a judgment. If the value is 0, the network is connected. If the value is not 0, the network is disconnected.

In fact, this does not need to call the dll

Easy built-in support library,
Connect to the internet ()
Online or not ()

Another is to use http to read webpages and determine whether the content is blank,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.