Hello Developers,
I have written a java code to find out whether wifi or data is connected in my device . The code is:
@SimpleFunction(description="Which one is connected data or wifi")
public String IsDataOrWifi(){
ConnectivityManager cm = (ConnectivityManager) this.context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
return info.getTypeName();
}
My Imports are:
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.content.Context;
@SimpleObject(external = true)
public class NetworkInfo extends AndroidNonvisibleComponent {
private ComponentContainer container;
private final Context context;
/**
* @param container container, component will be placed in
*/
public NetworkInfo(ComponentContainer container) {
super(container.$form());
this.container = container;
this.context = container.$context();
}
But the error is coming something like this:
[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/test/networkinfo/NetworkInfo.java:18: error: NetworkInfo is already defined in this compilation unit
[javac] import android.net.NetworkInfo;
[javac] ^
[javac] %SERVER_WORKSPACE%/appinventor/components/src/test/networkinfo/NetworkInfo.java:125: error: incompatible types: android.net.NetworkInfo cannot be converted to test.networkinfo.NetworkInfo
[javac] NetworkInfo info = cm.getActiveNetworkInfo();
[javac] ^
[javac] %SERVER_WORKSPACE%/appinventor/components/src/test/networkinfo/NetworkInfo.java:126: error: cannot find symbol
[javac] return info.getTypeName();
[javac] ^
[javac] symbol: method getTypeName()
[javac] location: variable info of type NetworkInfo
[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] 3 errors
[javac] 1 warning
stderr:
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: 8 seconds