you should do like this :
package com.salman.test;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiInfo;
import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.ComponentCategory;
@DesignerComponent(version = 1, description = "This Extension was created with the AppyBuilder Code Editor.<br>" +
"Create your own here:<br><a href='https://editor.appybuilder.com' target='_blank'>https://editor.appybuilder.com</a><br>",
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = "http://appyBuilder.com/extensions/icons/extension.png")
@SimpleObject(external = true)
public class Testing extends AndroidNonvisibleComponent {
private ComponentContainer container;
private int linkSpeed = 0;
public Testing(ComponentContainer container) {
super(container.$form());
this.container = container;
}
@SimpleFunction(description = "DESCRIPTION OF METHOD.")
public int GetWifiSpeed () {
WifiManager wifiManager = (WifiManager) container.$context().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
int linkSpeed = wifiInfo.getLinkSpeed();
}
return linkSpeed;
}
}
So the problem is you can't initialize the int in the code, you have to initialize the code outside the function. Works 100%