Need help to adding helper or drop down blocks in extension

Hello dear, Is this possible to add helper blocks/drop down blocks in extension using @Options annotation?

If possible then please help me to add helper blocks in extension project. I've tried many times but I can't do it.

If it's possible, it will be very helpful if you can send me an example project for Rush or Extension Template Repositories.

(Thanks in advance)

Try here:

1 Like

Yes, it is possible to include helper blocks in your extension. @BeksOmega has previously provided documentation on how to do that here (see §1.1). I have used these in a small extension that connects to some BLE-enabled scales in order to represent the supported units here.

As for the extension template repository, you need to clone it and provide your Java classes defining your extension following the guidelines in the extensions document. The necessary dependencies are listed in the README and there is an update-appinventor.sh script you need to run the first time to complete the rest of the setup process.

3 Likes

here is an example which I used for my battery manager extension App Inventor Extensions: Battery Manager | Pura Vida Apps

one of the helper classes looks like that (here for the Health helper blocks)

package com.puravidaapps.TaifunBattery.helpers;

import java.util.HashMap;
import java.util.Map;
import com.google.appinventor.components.common.OptionList;



/**
 * Defines a Health type
 */

public enum Health implements OptionList<String> {
  Cold("cold"),
  Dead("dead"),
  Good("good"),
  Overheat("overheat"),
  OverVoltage("over voltage"),
  Unknown("unknown"),
  UnspecifiedFailure("unspedified failure");


  private String health;

  Health(String h) {
    this.health = h;
  }


  public String toUnderlyingValue() {
    return health;
  }

  private static final Map<String, Health> lookup = new HashMap<>();

  static {
    for(Health h : Health.values()) {
      lookup.put(h.toUnderlyingValue(), h);
    }
  }

  public static Health fromUnderlyingValue(String h) {
    return lookup.get(h);
  }


}

in the main class I just added

import com.puravidaapps.TaifunBattery.helpers.*;

Taifun

1 Like

I've added helper blocks in my extension and everything is working after compiled the app, but I can't open companion app if this extension is using

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.