Hello guys.
Recently I wanted to learn to create extensions, so I started learning the basics of Java, and now I want to create my first extension, and I am trying to make a basic extension to get ringtone title.
I wrote a simple file using rush, but I am unable to build the extension.
package io.Teste;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.errors.YailRuntimeError;
import com.google.appinventor.components.runtime.util.YailList;
import android.media.Ringtone;
import android.content.Context;
import java.lang.Object;
public class Teste extends AndroidNonvisibleComponent {
public Teste(ComponentContainer container) {
super(container.$form());
}
@SimpleFunction(description = "Returns the sum of the given two integers.")
public int Sum(int a, int b) {
return a + b;
}
@SimpleFunction(description = "Return the ringtone title.")
public String getTitle (Context context) {
return getTitle;
}
}
The problem is here.
You can’t take the Context variable as a parameter in your extension. You will have to make the context variable wantin your java file and fill it in your class’s super constructor like this
context=container.$context
And you can use this anywhere wherever you want
P.S as @vknow360 said getTitle is not a variable or a parameter so you can’t return it.It will be the another error when you will solve the context error.
I think these things can be easily learnt by exploring open source extensions and basic Java tutorials.
Otherwise someday someone will just post "How to create a class? What is Java? How to create extension without learning Java? "