Android Determines network status

Source: Internet
Author: User

 Android  The application technique of determining network state is more important in practice. So, how does the Android operating system correctly determine if the network we're connected to is disconnected, hmm? Today we will conduct a detailed analysis of this application technique.

Public class Connectionchangereceiver extends 
broadcastreceiver 

@Override  
public void OnReceive (context context, Intent Intent)  

Connectivitymanager connectivitymanage R = 
(Connectivitymanager) Context.getsystemservice
(context.connectivity_service); &NBSP
Networkinfo activenetinfo = Connectivitymanager.
Getactivenetworkinfo ();  
Networkinfo mobnetinfo = Connectivitymanager.getnetworkinfo
( Connectivitymanager.type_mobile);  
if (activenetinfo!= null)  

Toast.maketext (Context, "Active network Type:" +&NBSP
Activenetinfo.gettypename (), Toast.length_short). Show ();  

if ( Mobnetinfo!= null)  

Toast.maketext (Context, "Mobile network Type:" + 
Mobnetinfo.gettyp Ename (), Toast.length_short). Show ();  



<!--Needed to check when the NETW ORK Connection ChAnges--> 
< Uses-permission android:name= "Android.permission.
Access_network_state "/> 
< Receiver android:name=" Com.blackboard.androidtest.
Receiver. Connectionchangereceiver " 
android:label=" networkconnection ">&NBSP;
< intent-filter> 
< Action android:name= "Android.net.conn.CONNECTIVITY_CHANGE"/>&NBSP;
</intent-filter> &NBSP
</receiver> 
The specific application of Android to determine the state of the network is introduced here.

Related Article

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.