Please Help... I'm trying to create extensions

Hello Expert... I want to create extension with Niotron.IDE
This Extension is to check wheter the mock location is ON/OFF
I will use this extensions to IF... THEN blocks...

If mocklocation = true then...
If mocklocation = false then...

I use this Code :

package com.android.MockTest;

import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;

@DesignerComponent(
version = 1,
description = "return Mock Setting on/off",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "")

@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "")

public class MockTest extends AndroidNonvisibleComponent {

//Activity and Context
private Context context;
private Activity activity;

public MockTest(ComponentContainer container){
    super(container.$form());
    this.activity = container.$context();
    this.context = container.$context();
}
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "False")

@SimpleProperty(userVisible = true)
public void boolean isMockSettingsON(Context context) {
    if (Settings.Secure.getString(context.getContentResolver(),Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
    return false;
else
    return true;
}


@SimpleFunction(description = "Sample Function Generated by Niotron")
public void TestFunction(){

}

@SimpleEvent(description = "Test Event Generated by Niotron")
public void TestEvent(){
    EventDispatcher.dispatchEvent(this, "TestEvent");
}

}

I Get This Error message

Started Compiling Project MockTest
Buildfile: /compiler/android/build.xml

javac:
[mkdir] Created dir: /compiler/android/build/urdaO/classes
[javac] Compiling 1 source file to /compiler/android/build/urdaO/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /compiler/android/src/urdaO/com/android/MockTest/MockTest.java:38: error: expected
[javac] public void boolean isMockSettingsON(Context context) {
[javac] ^
[javac] /compiler/android/src/urdaO/com/android/MockTest/MockTest.java:38: error: '(' expected
[javac] public void boolean isMockSettingsON(Context context) {
[javac] ^
[javac] /compiler/android/src/urdaO/com/android/MockTest/MockTest.java:38: error: invalid method declaration; return type required
[javac] public void boolean isMockSettingsON(Context context) {
[javac] ^
[javac] 3 errors
[javac] 1 warning

This is one of the mistakes.

Also, your indenting is not correct:

It should be:

if (Settings.Secure.getString(context.getContentResolver(),Settings.Secure.ALLOW_MOCK_LOCATION).equals("0")) {
     return true;
} else {return false;}

And simplified:

return Settings.Secure.getString(context.getContentResolver(),Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
2 Likes


Snip source : Android developer

I have try to modified but still error...

So it will be no way to identify that mock location setting is On/Off?
Thanks

1 Like

AFAIK, No.
But there might be a way...

1 Like

please show current code and the current error

You do not have brackets {} for if else. Try this:

@SimpleProperty(userVisible = true)
public boolean isMockSettingsON(Context context) {
    if (Settings.Secure.getString(context.getContentResolver(),Settings.Secure.ALLOW_MOCK_LOCATION).equals("0")) {
    return false;
   } else {
    return true;
}
}
2 Likes

Also, It shall be renamed to - IsMockSettingsOn (Naming Convention)

3 Likes

Yes.

By the way, @Ronald, you might not want to use this code. It does not support Android versions > 5.1, which most of our phones do not support.

1 Like

public class Reply extends MitAppInventorCommunity {
 System.out.println("I already said that...");
}

:rofl:

Yeah, I basically saw what you said.

1 Like

not gonna work there is 1 thing wrong Context cant be used as a parameter @Ronald has to use container.$context() instead

2 Likes

[quote="Aarush_Kumar, post:13, topic:48502"]

Here's my new code....
@SimpleProperty(userVisible = true)

public boolean isMockSettingsOn(Context context) {

if (Settings.Secure.getString(context.getContentResolver(),

    Settings.Secure.ALLOW_MOCK_LOCATION).equals("0")) {

return false;

} else {

return true;

}

}

And wont compiling with this message :

Started Compiling Project CekMockLocation
Buildfile: /compiler/android/build.xml

javac:
[mkdir] Created dir: /compiler/android/build/VZMXK/classes
[javac] Compiling 1 source file to /compiler/android/build/VZMXK/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /compiler/android/src/VZMXK/com/android/cekMockLocation/CekMockLocation.java:44: error: reached end of file while parsing
[javac] }
[javac] ^
[javac] 1 error
[javac] 1 warning

I have try this code.... but not compiling...

OK... Thanks for your correction....

Thanks for this information....

You mean this code ?
public CekMockLocation(ComponentContainer container){

    super(container.$form());

    this.activity = container.$context();

    this.context = container.$context();

}
1 Like

Remove the last }.

1 Like