【问题标题】:Detect Network Connection in Visual studio Xamarin crash android app在 Visual Studio Xamarin 崩溃 android 应用程序中检测网络连接
【发布时间】:2017-06-07 11:10:59
【问题描述】:

在我的第一个 Xamarin android 应用程序中,我遇到了另一个问题。 当我尝试检查连接时,应用程序崩溃了。

ConnectivityManager cm = (ConnectivityManager)GetSystemService(ConnectivityService);
NetworkInfo netInfo = cm.ActiveNetworkInfo;
if (netInfo.IsConnected)
{
  pictureSubText.Text = "Internet OK";
}
else
{
  pictureSubText.Text = "No Internet";
}

当遇到 if(netInfo.IsConnected) 时,App 崩溃并再次运行。 ACCESS_NETWORK_STATE、ACCESS_WIFI_STATE 和 INTERNET 在清单中检查。 如有任何帮助,我们将不胜感激。

--已更新--

似乎我使用的代码仅适用于 API 21+ 那么另一个问题 - 是否可以检查 API 小于 21 的互联网连接?

【问题讨论】:

    标签: android xamarin crash internet-connection


    【解决方案1】:

    下面的链接对你有用,

    也添加权限

    https://forums.xamarin.com/discussion/comment/276931#Comment_276931

    【讨论】:

      猜你喜欢
      • 2015-12-05
      • 1970-01-01
      • 1970-01-01
      • 2015-12-17
      • 1970-01-01
      • 2017-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多