Hello,
I would like to know how I can create an extension that contains npm packages.
For example: https://www.npmjs.com/package/wifi-speed
I use appybuilder code editor, is it possible with this program?
Thanks
Hello,
I would like to know how I can create an extension that contains npm packages.
For example: https://www.npmjs.com/package/wifi-speed
I use appybuilder code editor, is it possible with this program?
Thanks
NPM stands for node package manager and it use for javascript while extension are written in java so I think you can't use node module or NPM package in MIT app inventor extension
BTW appy builder code editor does not support external java package for building extension you can use app inventor source code or extension template for building extension with external library.
For external library you can find on Maven or you can contact to developer for jar file.
for what you have to use that package while you can do that programmatically
OK, thanks
ok, I will try it
Hello
I have made a code with what you have passed me, but it gives me the following error
Error: Config does not contain a field package failed auto detecting package info.
Code:
/** ~~~~~
- Created with the AppyBuilder Code Editor.
- This is a template for basic Extension.
- Modify this template to customize your extension.
- **** NOTE: DO NOT use a package name.
- **** The package name will be created for you automatically.
- **** Adding a package name will cause a compile error
/
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.
" +
"Create your own here:
https://editor.appybuilder.com
",
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = "http://appyBuilder.com/extensions/icons/extension.png")
@SimpleObject(external = true)
public class Internet_speed extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public Internet_speed(ComponentContainer container) {
super(container.$form());
this.container = container;
}@SimpleFunction(description = "Join two text.")
WifiManager wifiManager = getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
Integer linkSpeed = wifiInfo.getLinkSpeed(); //measured using WifiInfo.LINK_SPEED_UNITS
} return linkSpeed;}
As I see in code you are using WiFiManager for WiFi service for that you need to import class into your code.
I am new to java, how to import a class,
is this?
CustomObject myObject = new CustomObject();
Thanks
Please learn Java basics first, better than pasting code from the Internet
sorry, i speack straight forward
ok
could you tell me some page where I can find tutorials please
YouTube or GFG
Your welcome
Okay i will help you
First, to use the code you have to import this :
import android.net.wifi.WifiManager;
import android.net.wifi.WifiInfo;
Second Add the code I edited and learn what I changed :
@SimpleFunction(description = "")
public int GetWifiSpeed () {
WifiManager wifiManager = container.$context().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
Integer linkSpeed = wifiInfo.getLinkSpeed();
}
return linkSpeed;
}
Hello,
I've been looking at some tutorials...
Thank you very much for your help, I have added what you have told me, but I keep getting another error.
Code:>
/** ~~~~~
- Created with the AppyBuilder Code Editor.
- This is a template for basic Extension.
- Modify this template to customize your extension.
- **** NOTE: DO NOT use a package name.
- **** The package name will be created for you automatically.
- **** Adding a package name will cause a compile error
*/
package com.meulencv.Internet_speed;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.
" +
"Create your own here:
https://editor.appybuilder.com
",
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = "http://appyBuilder.com/extensions/icons/extension.png")
@SimpleObject(external = true)
public class Internet_speed extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public Internet_speed(ComponentContainer container) {
super(container.$form());
this.container = container;
}@SimpleFunction(description = "")
public int GetWifiSpeed () {
WifiManager wifiManager = container.$context().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
Integer linkSpeed = wifiInfo.getLinkSpeed();
}
return linkSpeed;}
}
Error:
Error: Failed execute ant extensions: Command executing error occured: code(1)stdout:
Buildfile: %SERVER_WORKSPACE%/appinventor/build.xmlextensions:
clean:
init:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/build/components
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/build
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/build/classes
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/reports
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/reports/raw
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/reports/htmlCommonConstants:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/build/classes/CommonConstants
[javac] Compiling 7 source files to %SERVER_WORKSPACE%/appinventor/components/build/classes/CommonConstants
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[javac] Creating empty %SERVER_WORKSPACE%/appinventor/components/build/classes/CommonConstants/com/google/appinventor/components/common/package-info.class
[jar] Building jar: %SERVER_WORKSPACE%/appinventor/build/components/CommonConstants.jar
[jar] Building jar: %SERVER_WORKSPACE%/appinventor/build/components/CommonConstants-gwt.jarHtmlEntities:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/build/classes/HtmlEntities
[javac] Compiling 1 source file to %SERVER_WORKSPACE%/appinventor/components/build/classes/HtmlEntities
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[jar] Building jar: %SERVER_WORKSPACE%/appinventor/components/build/HtmlEntities.jarcommon_CommonVersion:
init:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/build/common
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/build
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/build/classes
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/reports
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/reports/raw
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/reports/htmlCommonVersion:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/build/classes/CommonVersion
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/build/src/com/google/appinventor/common/version
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/common/build/src/com/google/appinventor/common/version
[javac] Compiling 3 source files to %SERVER_WORKSPACE%/appinventor/common/build/classes/CommonVersion
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[javac] Creating empty %SERVER_WORKSPACE%/appinventor/common/build/classes/CommonVersion/com/google/appinventor/common/version/package-info.class
[jar] Building jar: %SERVER_WORKSPACE%/appinventor/build/common/CommonVersion.jar
[jar] Building jar: %SERVER_WORKSPACE%/appinventor/build/common/CommonVersion-gwt.jarCopyComponentLibraries:
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps/armeabi-v7a
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps/arm64-v8a
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps/x86_64
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 57 files to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 2 files to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/depsAndroidRuntime:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/build/classes/AndroidRuntime
[javac] Compiling 266 source files to %SERVER_WORKSPACE%/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] %SERVER_WORKSPACE%/appinventor/components/src/com/meulencv/Internet_speed/Internet_speed.java:41: error: incompatible types: Object cannot be converted to WifiManager
[javac] WifiManager wifiManager = container.$context().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
[javac] ^
[javac] %SERVER_WORKSPACE%/appinventor/components/src/com/meulencv/Internet_speed/Internet_speed.java:46: error: cannot find symbol
[javac] return linkSpeed;
[javac] ^
[javac] symbol: variable linkSpeed
[javac] location: class Internet_speed
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 2 errors
[javac] 1 warningstderr:
BUILD FAILED
%SERVER_WORKSPACE%/appinventor/build.xml:42: The following error occurred while executing this line:
%SERVER_WORKSPACE%/appinventor/components/build.xml:193: The following error occurred while executing this line:
%SERVER_WORKSPACE%/appinventor/build-common.xml:125: Compile failed; see the compiler error output for details.Total time: 14 seconds
can you help me, please?
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 = "WRITE DISCRIPTION OF YOUR EXTENSION",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "ICON URL OF YOUR EXTENSION")
@SimpleObject(external = true)
public class Internet_speed extends AndroidNonvisibleComponent {
private ComponentContainer container;
public Internet_speed(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();
int linkSpeed = 0;
if (wifiInfo != null) {
int linkSpeed = wifiInfo.getLinkSpeed();
}
return linkSpeed;
}
}
please start with the basic extension because extension development is not easy for a beginner. you are doing some basic mistake like
Type Casting Error
Use Primitive DataTypes
Implement Perfect Logic
what happened in the case of wifiInfo = null
in that case local variable linkSpeed is not defined so that you can't return it. see into your error