What is the correct way of checking for mobile network available (no data connection)

后端 未结 6 683
名媛妹妹
名媛妹妹 2021-02-02 15:35

What is the correct way of checking if a mobile network (GSM) connection is available on Android? (>2.1) I don\'t want to check if there is data connection available over the mo

6条回答
  •  逝去的感伤
    2021-02-02 16:21

    I believe this will do the job..

    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            if (manager != null) {
                NetworkInfo info = manager.getActiveNetworkInfo();
                if (info != null && info.isConnected()) {
                    networkAvailable = true;
                }
    

提交回复
热议问题