我想在我的 android 应用程序中显示连接不可用的警报。
我在我的应用程序中调用了一些休息请求。为了检查这种网络不可用情况,我手动断开了笔记本电脑中的 wifi(我正在模拟器中进行测试)。
我称之为服务的代码在这里
resp = client.execute(httpPostRequest);
在这里我遇到了异常
catch (IllegalStateException e) {
            //assertTrue(e.getLocalizedMessage(), false);
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            //assertTrue(e.getLocalizedMessage(), false);
            e.printStackTrace();
        } catch (IOException e) {
            //assertTrue(e.getLocalizedMessage(), false);
            e.printStackTrace();
        }
当我遇到异常时,我尝试使用此功能获取设备网络连接的状态
public boolean IsInternetConnectted()
    {
        ConnectivityManager conMgr =  (ConnectivityManager)this.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo i = conMgr.getActiveNetworkInfo();
        conMgr = null;
        if (i == null)
            return false;
        if (!i.isConnected())
            return false;
        if (!i.isAvailable())
            return false;
        return true;        
    }
即使 wi-fi 断开连接,我的模拟器也会从此函数返回 true。
这种情况怎么解决??