NPM extension question

I strongly recommend you please start with basic and learn some basic core concept of JAVA because we have lots of hope from you.

every extension developer made something new which helps community so best of luck for extension development.

please fell free to ask question

1 Like

Thanks for all :slight_smile:

Oh sorry that was my mistake, I forgot to change the integer :sweat_smile:

1 Like

Thank you for fixing the code but I suggest you to don't need to add this line :

 int linkSpeed = 0;

because it's not important, it's like you initialized the integer twice

1 Like

no my dear friend in case of wifiInfo = null linkSpeed is not defined.

2 Likes

OH, okay i will check

1 Like

see this error

2 Likes

oh yeah i think you are right but it still error

1 Like

show me error

1 Like

OKay i got it

1 Like

its still error because you initialize it on the code

1 Like

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%

2 Likes

no it not required
according to me why we need to create one instance variable of object because we need only value at runtime after method execution we are not interested in linkSpeed but if we create instance variable then it will stored into heap memory.

1 Like

then why don't you try compiling the code you edited? I've tried compiling the code you edited and it doesn't work.

and the code that I have edited works 100%

1 Like

Are you sure Salman? That would just return the value 0.

1 Like

i think im sure sir :sweat_smile:
please guide me if I am wrong

1 Like

please follow the naming conventions

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

1 Like