How can I tell if my Android phone is currently connected?

Source: Internet
Author: User

If you want to develop a network application program, first consider whether to access the network, in the Android phone to determine whether the Internet can be

The IsAvailable () method of the Connectivitymanager class is judged,

First get an example of a network communication class:

Java code
    1. Connectivitymanager cwjmanager= (Connectivitymanager) Getsystemservice (Context.connectivity_service);

Use

Java code
    1. Cwjmanager.getactivenetworkinfo (). isavailable ();

To return is valid, if True indicates that the current Android phone is connected, possibly WiFi or GPRS, HSDPA, etc.

The detailed access method can be judged by the Getactivenetworkinfo () method of the Connectivitymanager class,

Note that the call needs to be added to the

XML code
    1. <uses-permission android:name="Android.permission.ACCESS_NETWORK_STATE"></ Uses-permission>

This permission, the Android Development network reminds everyone on the real computer market and the browser program used this method to determine whether to continue, while some network time-out can also check the presence of network connections, so as not to waste the power resources on the phone.

How can I tell if my Android phone is currently connected?

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.