Hi all,
I want to turn on a HotSpot on my tablet with Android 7.1.2 but it doesn't work.
Here is my Java-code. The return value is "Error in method.invoke(wifiManager, netConfig, enable)"
On a tablet with Android 5.1.1 it works! What is the problem?
Lutz
I want to turn on a HotSpot on my tablet with Android 7.1.2 but it doesn't work.
Here is my Java-code. The return value is "Error in method.invoke(wifiManager, netConfig, enable)"
B4X:
#If JAVA
import android.text.SpannableStringBuilder;
import android.text.Spannable;
import android.widget.TextView;
import android.view.View;
import android.content.Context;
import android.graphics.Color;
import android.text.style.ImageSpan;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public String SetAccessPoint(boolean enable, String SSID, String PASS, Context context) {
String name;
name = "leer";
WifiManager wifiManager = (WifiManager) context.getSystemService("wifi");
if(enable){
wifiManager.setWifiEnabled(!enable); // Disable all existing WiFi Network
}
else {
if(!wifiManager.isWifiEnabled())
wifiManager.setWifiEnabled(!enable);
}
Method[] methods = wifiManager.getClass().getDeclaredMethods();
for (Method method : methods) {
if (method.getName().equals("setWifiApEnabled")) {
name = method.getName();
WifiConfiguration netConfig = new WifiConfiguration();
netConfig.SSID = SSID;
netConfig.preSharedKey = PASS;
netConfig.allowedKeyManagement.set(1);
netConfig.allowedAuthAlgorithms.set(0);
try {
method.invoke(wifiManager, netConfig, enable);
} catch (Exception ex) {
name = "Error in method.invoke(wifiManager, netConfig, enable)";
}
break;
}
}
return name;
}
#END IF
On a tablet with Android 5.1.1 it works! What is the problem?
Lutz