zoukankan      html  css  js  c++  java
  • android 判断网络是否断开

    引用:http://wang-peng1.iteye.com/blog/557362

    public class ConnectionChangeReceiver extends BroadcastReceiver 
    { 
      
    @Override 
      
    public void onReceive( Context context, Intent intent ) 
      
    { 
        
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE ); 
        
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); 
        
    NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(     ConnectivityManager.TYPE_MOBILE ); 
        
    if ( activeNetInfo != null ) 
        
    { 
          
    Toast.makeText( context, "Active Network Type : " + activeNetInfo.getTypeName(), Toast.LENGTH_SHORT).show(); 
        
    } 
        
    if( mobNetInfo != null ) 
        
    { 
          
    Toast.makeText( context, "Mobile Network Type : " + mobNetInfo.getTypeName(), Toast.LENGTH_SHORT).show(); 
        
    } 
      
    } 
    } 
    <!-- Needed to check when the network connection changes --> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 


    <receiver android:name="com.blackboard.androidtest.receiver.ConnectionChangeReceiver" 
              
    android:label="NetworkConnection"> 
      
    <intent-filter> 
        
    <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/> 
      
    </intent-filter> 
    </receiver> 

  • 相关阅读:
    SQL中的数字格式化 (收藏)
    read about用法
    run into用法
    shoot for用法
    take off用法
    英语成语
    bring up用法
    satisfy with用法
    spend用法
    Linux环境进程间通信:共享内存
  • 原文地址:https://www.cnblogs.com/sode/p/2813348.html
Copyright © 2011-2022 走看看