Exsent-Project: Create your own functions

Valentin Ahrend
6 min readFeb 25, 2021

In this short sheet you will learn how to program your own functions for the Exsent Project.

Additional information -> Language: Java, UI-Language: Java (also XML), Difficulty: Easy-Medium

Your idea

Before you start make sure you have an idea and check if this functions does not already exist. It can be anything you want to program,

but always remember that it has to follow the Google Play Store Rules (https://play.google.com/intl/en/about/developer-content-policy)

Also only good functions that follows these rules will be verified.

Step 1: Create the basics

Open Android Studio and create a new project.

Step 2: Setup

Past the following code in your project-level build.gradle file

build.gradle(Project)

Past the following code in your app-level build.gradle file.

build.gradle(app)

Step 3: Environment

By building a function you do not use the res directory. You always use the assets dir.

Your function name is a single name, which acts like your function id. It should be unique.

Understanding the Cloud environment

The cloud consists out of three files:

  • Source.jar

Source.jar is a file containing the source files and code of your function.

  • Contents.zip

A compressed file containing a .json file named FunctionName.json and a low resolution image.

  • Focus.zip

A compressed file containing .png/.jpg images with a higher resolution than the image from Contents.zip

Create a file in the assets folder named “YourFunctionName.json”. YourFunctionName should be your real function name. Paste the following text into this json file:

{ 
"n": "FunctionABX",
"s": "Short subtitle",
"a": "Author",
"i": "Some info",
"v": "version",
"ic": "init_class_package.init_class_name",
"b": isBeta,
"o":"download url of the Contents.zip file see above!",
"su":"download url of the Source.jar file see above!",
"u":"download url of the Focus.zip file see above!",
"d": "your website",
"c": category_int,
"l": "languages_as_list",
"x": number_of_files_in_focus_zip}

Explaining the .json parameters

  • “n”: Her stands your Function Name, it should by unique!
  • “s”: This is a short subtitle, example: “A powerful machine” or “Best game ever”
  • “a”: The name of the author/dev of the function
  • “i”: Information about the function. What are the main features? What does it do?
  • “v”: The version of the function
  • “ic”: The file path of the main function class. Example: com.myfunction.va.MyFunction (without .class at the end)
  • “b”: Is this a beta version?
  • “o”: The download link of your Contents.zip file, should be public and should be fast
  • “su”: The download link of your Source.jar file, should be public and should be fast
  • “u”: The download link of your Focus.zip file, should be public and should be fast
  • “d”: Your company website, if you don’t have any, type: “”
  • “c”: The category tag. This enum shows the int parameter matching each category name:
public enum Category {

Books(0),
Business(1),
Developer_Tools(2),
Education(3),
Entertainment(4),
Finance(5),
Food_and_Drink(6),
Games(7),
Graphics_and_Design(8),
Health_and_Fitness(9),
Lifestyle(10),
Magazines_and_Newspapers(11),
Medical(12),
Music(13),
Navigation(14),
News(15),
Photo_and_Video(16),
Productivity(17),
Reference(18),
Shopping(19),
Social_Networking(20),
Sports(21),
Travel(22),
Utilities(23),
Weather(24);
}
  • “l”: Language int tags as list. Here is a file of each language tag: https://gist.github.com/ValentinAhrend/71d4afbdc58715dd48d3eaa632d48627 Please use the line number as int value. As an example: If you want to say that your languages are “German,English,French”. You search for the value and type down the line number. The result is “87,110,248”.
  • “x”: Put here the number of files in Focus.zip. The minimum amount is 1, because you need to put there a higher resolution picture of your function image (like an app icon). The other files are images in that are sized like the default android phone size. These files should be in-function-images.

Be sure that you have entered the data correctly. This file is the most important key to your function.

Code Environment

In your project, you created the MainActivity.java file. This file will be the starter file of the function service. You need to paste the following code into the onCreate method. All data should equal the values from your Contents.json file.

FunctionHandler1.loaded_classes.put("Name of your function",MyFunction.class);SecureFile.SecureFileSave.setSecureFile(new SecureFile());

Intent opener = new Intent(getApplicationContext(), Function.class);
opener.putExtra("function_id", id_of_your_function);
opener.putExtra("function_version", version_of_your_function);
opener.putExtra("function_beta", true);
opener.putExtra("function_name", "Name of your function");
opener.putExtra("function_author", "Name of the dev");

startActivity(opener);

Step 4: Create the function

Create a new file, in this case MyFunction.java (see above).

Important

You need to setup a constructor with a parameter of the Function class. This param. should be passed to its super: super(param);

You will have a field value called function. This field is like a controller for all your actions. If you want to do something you always have to use the function field to call it. Examples will follow.

This is how MyFunction.java looks now

public class MyFunction extends Function {



public MyFunction(Function f){super(f);}


}

Examples

  • Build an onCreate method and setup a contentView:
@Override
public void onCreate(Bundle var0) {
function.onCreate(var0);//use function

View contentView = new View(function);/*function also used as context*/
contentView.setBackgroundColor(Color.RED);

function.setContentView(contentView);

}
  • Create a file
public void createFile() throws IOException {
final File f = new File(function.getFilesDir()+"/MyFile.txt");
function.writeFile(f, "this is my cool file!");
}
  • Read file
public String readFile(){
final File f = new File(function.getFilesDir()+"/MyFile.txt");
return Function.Utils.readFile(f);
}

Important

The file system of your function looks like this:

— com.exsent.app:

— — app_all+your_function_id

— — — assets (your assets) (dir)

— — — files (your files) (dir)

— — cache

— — — func+your_function_id (dir)

All other paths are denied and will cause a crash. (normally)

We can’t prevent the user completely from malware. So I, the developer, just hope that you think about malware and it’s consequences… 👍

If you have any questions you can always contact us by wizard.exsent@gmail.com

If you want to add resource files (like drawables) you have to store them in the assets folder.

Step 5: Finish

As I already said you need to upload these three files (Contents.zip, Focus.zip, Source.jar).

Building Source.jar:

You have to get the .class files of your project.

Important: This means that you are not able to use gradle implementations. You have to integrate them in your own app files, because you have to get the .class files of them. If you have the raw .class files, you can of course use them too!

  • Build your project
  • go to build/intermediates/javac/debug/classes
  • reveal the dir in finder/explorer
  • Compress all these .class files to a .zip file.
  • Merge other .class files (if you need to), maybe from implementations
  • Merge your assets folder into this .zip file.
  • Rename the ending from .zip to .jar.
  • Finish: Source.jar

Important: Check whether a dir filled with .class files is named assets. Two assets dirs would be a huge problem.

Building Contents.zip:

You have to get the FunctionName.json file and a small image (like an app-icon). The image will be used as a preview and small icon. It should be named FunctionName.png/.jpg (should be a square)

Compress both files to Contents.zip. (finish)

Building Focus.zip:

This .zip files contains some bigger images.

  • There must be an image called FunctionName.jpg/.png. This image is used as better function icon. (should be a square).
  • There can be a few other photos (sized like android default size), that show how your function looks like, or what it does or anything you want. You can compare it to the icons from Apple AppStore.
  • Merge all photos together to a .zip file.
  • Finish: Focus.zip

Now: Upload all files to your opened database (example: Firebase)

Next Step: Go to the gallery in the ExsentApp. Click on the plus. Solve the Java-Problem. Put the requested urls in the EditText fields. And send these urls!

You will get notified, if it functioned successfully.

Have a nice day!

--

--

Valentin Ahrend

Self taught software developer. Sharing some ideas, experiences and projects.