Plugin is the base class for all plugins, containing a number of convenient features for interacting with the Bridge, managing plugin permissions, tracking lifecycle events, and more. You should inherit from this class when creating new plugins, along with adding the CapacitorPlugin
| 42 | * metadata about the Plugin |
| 43 | */ |
| 44 | public class Plugin { |
| 45 | |
| 46 | // The key we will use inside of a persisted Bundle for the JSON blob |
| 47 | // for a plugin call options. |
| 48 | private static final String BUNDLE_PERSISTED_OPTIONS_JSON_KEY = "_json"; |
| 49 | |
| 50 | // Reference to the Bridge |
| 51 | protected Bridge bridge; |
| 52 | |
| 53 | // Reference to the PluginHandle wrapper for this Plugin |
| 54 | protected PluginHandle handle; |
| 55 | |
| 56 | /** |
| 57 | * A way for plugins to quickly save a call that they will need to reference |
| 58 | * between activity/permissions starts/requests |
| 59 | * |
| 60 | * @deprecated store calls on the bridge using the methods |
| 61 | * {@link com.getcapacitor.Bridge#saveCall(PluginCall)}, |
| 62 | * {@link com.getcapacitor.Bridge#getSavedCall(String)} and |
| 63 | * {@link com.getcapacitor.Bridge#releaseCall(PluginCall)} |
| 64 | */ |
| 65 | @Deprecated |
| 66 | protected PluginCall savedLastCall; |
| 67 | |
| 68 | // Stored event listeners |
| 69 | private final Map<String, List<PluginCall>> eventListeners; |
| 70 | |
| 71 | /** |
| 72 | * Launchers used by the plugin to handle activity results |
| 73 | */ |
| 74 | private final Map<String, ActivityResultLauncher<Intent>> activityLaunchers = new HashMap<>(); |
| 75 | |
| 76 | /** |
| 77 | * Launchers used by the plugin to handle permission results |
| 78 | */ |
| 79 | private final Map<String, ActivityResultLauncher<String[]>> permissionLaunchers = new HashMap<>(); |
| 80 | |
| 81 | private String lastPluginCallId; |
| 82 | |
| 83 | // Stored results of an event if an event was fired and |
| 84 | // no listeners were attached yet. Only stores the last value. |
| 85 | private final Map<String, List<JSObject>> retainedEventArguments; |
| 86 | |
| 87 | public Plugin() { |
| 88 | eventListeners = new HashMap<>(); |
| 89 | retainedEventArguments = new HashMap<>(); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Called when the plugin has been connected to the bridge |
| 94 | * and is ready to start initializing. |
| 95 | */ |
| 96 | public void load() {} |
| 97 | |
| 98 | /** |
| 99 | * Registers activity result launchers defined on plugins, used for permission requests and |
| 100 | * activities started for result. |
| 101 | */ |
nothing calls this directly
no outgoing calls
no test coverage detected