How to provide option to select wi-fi or GPRS for network connectivity in android app

前端 未结 3 994
渐次进展
渐次进展 2020-12-05 20:50

In my app i want to provide the user with the option to choose wi-fi / GPRS for network connectivity to the web server. May be answers to the following ques solve my prob ..

3条回答
  •  没有蜡笔的小新
    2020-12-05 21:23

    You can provide option to user on screen using following code block....

     public static ShowAvailable() 
     {
       ConnectivityManager connectivityMgr = (ConnectivityManager)
       getSystemService(Context.CONNECTIVITY_SERVICE);
       NetworkInfo[] nwInfos = connectivityMgr.getAllNetworkInfo(); 
           for (NetworkInfo nwInfo : nwInfos)  
              {  
                 Log.d(TAG, "Network Type Name: " +
                 nwInfo.getTypeName());   Log.d(TAG, "Network available: " +
                 nwInfo.isAvailable());   Log.d(TAG, "Network c_or-c: " +
                 nwInfo.isConnectedOrConnecting());   Log.d(TAG, "Network connected: "
                 + nwInfo.isConnected()); 
              }
    
    }
    

提交回复
热议问题