- Home /
Question by
kahlerasse · Aug 16, 2018 at 10:04 PM ·
c#androidunity 2d
can't enable wifi in unity on android device [duplicate]
i am tried to enable wifi on my android device for hours but it di not work i searched all the possible solutions and they didn't work please help this is my code :
using System;
using UnityEngine;
using UnityEngine.UI;
public class PluginWrapper : MonoBehaviour {
public Text text;
// Use this for initialization
void Awake () {
setWifiEnabled(true);
}
public bool setWifiEnabled(bool enabled)
{
try
{
using (AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity"))
{
using (var wifiManager = activity.Call<AndroidJavaObject>("getSystemService", "wifi"))
{
return wifiManager.Call<bool>("setWifiEnabled", enabled);
}
}
}
catch (Exception e)
{
}
return false;
}
}
and this is the manifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<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>
</manifest>
i tried this answer but didnt work Enable/Disable Wifi on Android in Unity
unity version : 2018.1.8f1
android version : 6.0.1
manifest.xml: assets/Plugins/Android/libs/manifest.xml with AndroidPlugins.jar
Comment
Best Answer
Answer by kahlerasse · Aug 17, 2018 at 01:05 PM
i needed to follow the step number 1 in the answer in here and then add <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
and <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
and it worked