0

我有一个像这样检查网络连接状态的项目:

public void GetStatus ()
{
    ConnectivityManager oManager;
    ConnectivityState eState;
    //
    oManager = (ConnectivityManager)m_oContext.GetSystemService (Activity.ConnectivityService);
    //
    if (oManager.ActiveNetworkInfo == null)
        Connected = false;
    else
        Connected = oManager.ActiveNetworkInfo.IsConnected;
    //
    // Get the current connection state
    if (!Connected) 
        eState = ConnectivityState.NotConnected;
    else if (oManager.GetNetworkInfo (ConnectivityType.Mobile).GetState () == NetworkInfo.State.Connected) 
        eState = ConnectivityState.Roaming;
    else if (oManager.GetNetworkInfo (ConnectivityType.Wifi).GetState () == NetworkInfo.State.Connected)
        eState = ConnectivityState.WiFi;
    else
        eState = ConnectivityState.Other;
    //
    State = eState;
    //
    if (StatusUpdated != null)
        StatusUpdated ();
}

这在从 Xamarin Studio 运行时运行良好,但现在我已将我的项目移至 Visual Studio 2012,它不会获取清单中设置的权限。这是我在清单中的内容:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="MyApp.Android">
    <uses-sdk android:targetSdkVersion="10" android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application android:label="My App"></application>
</manifest>

我通过转到解决方案的属性并选择从那里创建它来创建清单文件,然后选中复选框,ACCESS_NETWORK_STATE但当我从 VS2012 运行时仍然出现异常,说设备没有权限。对此有什么帮助吗?谢谢。

4

0 回答 0