How to get wifi hotspot state

前端 未结 4 793
我寻月下人不归
我寻月下人不归 2021-01-06 00:54

I am creating wifi hotspot in my phone and I want get its state change event when I switched on or off hotspot.

4条回答
  •  孤城傲影
    2021-01-06 01:00

    try this

    Write this code into OnCreate() method

    ConnectivityManager cm = (ConnectivityManager) getSystemService(con.CONNECTIVITY_SERVICE);
            NetworkInfo netInfo = cm.getActiveNetworkInfo();
            if (netInfo != null && netInfo.isConnectedOrConnecting()) {
    
                Success 
            }
    
            else {
                           Give Some Error Message
                 }
    

    also mention necessary permission to manifest file

提交回复
热议问题