Android判斷當前行動電話通訊

來源:互聯網
上載者:User

我最後使用的辦法,網路上搜到的:

    public class NetworkUtils {    public final static int NONE = 0;    //無網路    public final static int WIFI = 1;    //Wi-Fi    public final static int MOBILE = 2;    //3G,GPRS    /** * 擷取當前網路狀態    * @param context    * @return    */    public static int getNetworkState(Context context){    ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);    //行動電話通訊判斷    State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();    if(state == State.CONNECTED||state == State.CONNECTING){    return MOBILE;    }    //Wifi網路判斷    state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();    if(state == State.CONNECTED||state == State.CONNECTING){    return WIFI;    }    return NONE;    }    } 

1.從API 16開始,有了這個方法:isActiveNetworkMetered
(),判斷當前網路是否是計費網路,但是從16才開始有,那麼16之前的怎麼判斷呢?
2.有時候你需要監聽網路的變化,比如你做了一個下載的管理器,當網路消失的適合,你需要能夠暫停,當網路有的適合,你需要能夠繼續下載。
http://blog.csdn.net/hehe9737/article/details/7477511

android監聽網路變化問題

http://www.eoeandroid.com/forum.php?mod=viewthread&tid=209190&fromuid=511991

(出處: eoe Android開發人員社區)

如何避免網路變化的多次廣播

http://www.eoeandroid.com/forum.php?mod=viewthread&tid=193562&fromuid=511991

(出處: eoe Android開發人員社區)
http://developer.android.com/reference/android/telephony/PhoneStateListener.html

http://www.eoeandroid.com/forum.php?mod=viewthread&tid=193562
如何避免網路變化的多次廣播

http://www.eoeandroid.com/forum.php?mod=viewthread&tid=193562&fromuid=511991

(出處: eoe Android開發人員社區)

http://www.apkbus.com/android-66880-1-1.html










相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.