我试图在我的android设备上启用wifi几个小时,但它无法正常工作,我搜索了所有可能的解决方案,但它们均无法正常工作,请帮助 这是我的代码:
using System;
using UnityEngine;
public class PluginWrapper : MonoBehaviour {
// Use this for initialization
void Start () {
setWifiEnabled(true);
}
public bool setWifiEnabled(bool enabled)
{
try{
AndroidJavaClass javaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = javaClass.GetStatic<AndroidJavaObject>("currentActivity");
var wifiManager = activity.Call<AndroidJavaObject>("getSystemService", "wifi");
wifiManager.Call<bool>("setWifiEnabled", enabled);
}
catch (Exception e)
{
Debug.LogError(e.Data);
}
return false;
}
}
这是manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
</application>
我尝试了这个答案,但是没有用 Enable/Disable Wifi on Android in Unity
统一版本:2018.1.8f1
android版本:6.0.1
manifest.xml:具有AndroidPlugins.jar的Assets / Plugins / Android / libs / manifest.xml