From 002f1e55173a50b9fe918b4eda73b5113b713282 Mon Sep 17 00:00:00 2001 From: Carl Poole Date: Mon, 8 Feb 2021 11:43:10 -0600 Subject: [PATCH] feat(android): activity result use new API and update permission result callbacks to match (#4127) --- .../main/java/com/getcapacitor/Bridge.java | 57 ++-- .../java/com/getcapacitor/BridgeActivity.java | 22 +- .../main/java/com/getcapacitor/Plugin.java | 320 ++++++++++-------- .../java/com/getcapacitor/PluginHandle.java | 2 +- .../java/com/getcapacitor/PluginMethod.java | 6 - .../annotation/ActivityCallback.java | 11 + .../annotation/CapacitorPlugin.java | 12 +- .../annotation/PermissionCallback.java | 11 + 8 files changed, 248 insertions(+), 193 deletions(-) create mode 100644 android/capacitor/src/main/java/com/getcapacitor/annotation/ActivityCallback.java create mode 100644 android/capacitor/src/main/java/com/getcapacitor/annotation/PermissionCallback.java diff --git a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java index 940914c746..48404aa7d2 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java @@ -484,6 +484,7 @@ public PluginHandle getPlugin(String pluginId) { * @param requestCode * @return */ + @Deprecated public PluginHandle getPluginWithRequestCode(int requestCode) { for (PluginHandle handle : this.plugins.values()) { int[] requestCodes; @@ -501,13 +502,11 @@ public PluginHandle getPluginWithRequestCode(int requestCode) { } requestCodes = legacyPluginAnnotation.requestCodes(); - } else { - requestCodes = pluginAnnotation.requestCodes(); - } - for (int rc : requestCodes) { - if (rc == requestCode) { - return handle; + for (int rc : requestCodes) { + if (rc == requestCode) { + return handle; + } } } } @@ -638,6 +637,12 @@ public PluginCall getSavedCall(String callbackId) { return this.savedCalls.get(callbackId); } + PluginCall getPluginCallForLastActivity() { + PluginCall pluginCallForLastActivity = this.pluginCallForLastActivity; + this.pluginCallForLastActivity = null; + return pluginCallForLastActivity; + } + /** * Release a retained call * @param call @@ -900,36 +905,36 @@ protected Map getPermissionStates(Plugin plugin) { * @param resultCode * @param data */ - public void onActivityResult(int requestCode, int resultCode, Intent data) { + boolean onActivityResult(int requestCode, int resultCode, Intent data) { PluginHandle plugin = getPluginWithRequestCode(requestCode); if (plugin == null || plugin.getInstance() == null) { Logger.debug("Unable to find a Capacitor plugin to handle requestCode, trying Cordova plugins " + requestCode); - cordovaInterface.onActivityResult(requestCode, resultCode, data); - return; + return cordovaInterface.onActivityResult(requestCode, resultCode, data); } - // deprecated, to be removed - PluginCall lastCall = plugin.getInstance().getSavedCall(); + CapacitorPlugin pluginAnnotation = plugin.getPluginClass().getAnnotation(CapacitorPlugin.class); + if (pluginAnnotation == null) { + // deprecated, to be removed + PluginCall lastCall = plugin.getInstance().getSavedCall(); + + // If we don't have a saved last call (because our app was killed and restarted, for example), + // Then we should see if we have any saved plugin call information and generate a new, + // "dangling" plugin call (a plugin call that doesn't have a corresponding web callback) + // and then send that to the plugin + if (lastCall == null && pluginCallForLastActivity != null) { + plugin.getInstance().saveCall(pluginCallForLastActivity); + } + + plugin.getInstance().handleOnActivityResult(requestCode, resultCode, data); - // If we don't have a saved last call (because our app was killed and restarted, for example), - // Then we should see if we have any saved plugin call information and generate a new, - // "dangling" plugin call (a plugin call that doesn't have a corresponding web callback) - // and then send that to the plugin - if (lastCall == null && pluginCallForLastActivity != null) { - plugin.getInstance().saveCall(pluginCallForLastActivity); - } + // Clear the plugin call we may have re-hydrated on app launch + pluginCallForLastActivity = null; - CapacitorPlugin pluginAnnotation = plugin.getPluginClass().getAnnotation(CapacitorPlugin.class); - if (pluginAnnotation != null) { - // Use new callback with new @CapacitorPlugin plugins - plugin.getInstance().handleOnActivityResult(pluginCallForLastActivity, requestCode, resultCode, data); + return true; } else { - plugin.getInstance().handleOnActivityResult(requestCode, resultCode, data); + return false; } - - // Clear the plugin call we may have re-hydrated on app launch - pluginCallForLastActivity = null; } /** diff --git a/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java b/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java index e7bbf95b69..651aeba70e 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java +++ b/android/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java @@ -191,15 +191,31 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in } } + /** + * Handles activity results. + * + * Capacitor is backwards compatible such that plugins using legacy activity result codes + * may coexist with plugins using the AndroidX Activity v1.2 activity callback flow introduced + * in Capacitor 3.0. + * + * In this method, plugins are checked first for ownership of the legacy request code. If the + * {@link Bridge#onActivityResult(int, int, Intent)} method indicates it has handled the activity + * result, then the callback will be considered complete. Otherwise, the result will be handled + * using the AndroidX Activiy flow. + * + * @param requestCode the request code associated with the activity result + * @param resultCode the result code + * @param data any data included with the activity result + */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (this.bridge == null) { return; } - this.bridge.onActivityResult(requestCode, resultCode, data); + if (!bridge.onActivityResult(requestCode, resultCode, data)) { + super.onActivityResult(requestCode, resultCode, data); + } } @Override diff --git a/android/capacitor/src/main/java/com/getcapacitor/Plugin.java b/android/capacitor/src/main/java/com/getcapacitor/Plugin.java index 463e5643b4..d818bd25c8 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Plugin.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Plugin.java @@ -7,16 +7,18 @@ import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; +import androidx.activity.result.ActivityResult; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; +import com.getcapacitor.annotation.ActivityCallback; import com.getcapacitor.annotation.CapacitorPlugin; import com.getcapacitor.annotation.Permission; +import com.getcapacitor.annotation.PermissionCallback; import com.getcapacitor.util.PermissionHelper; -import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; @@ -66,15 +68,17 @@ public class Plugin { private final Map> eventListeners; /** - * Base activity result launcher used by the {@link #requestPermissions(PluginCall)} plugin call + * Launchers used by the plugin to handle activity results */ - private ActivityResultLauncher basePermissionLauncher = null; + private final Map> activityLaunchers = new HashMap<>(); /** - * Launchers used by the plugin to request permissions + * Launchers used by the plugin to handle permission results */ private final Map> permissionLaunchers = new HashMap<>(); + private String lastPluginCallId; + // Stored results of an event if an event was fired and // no listeners were attached yet. Only stores the last value. private final Map retainedEventArguments; @@ -91,87 +95,118 @@ public Plugin() { public void load() {} /** - * Registers the permission launchers used by the {@link #requestPermissions(PluginCall)} plugin call and - * those defined on plugins + * Registers activity result launchers defined on plugins, used for permission requests and + * activities started for result. */ - void initializePermissionLaunchers() { - basePermissionLauncher = - bridge - .getActivity() - .registerForActivityResult( - new ActivityResultContracts.RequestMultiplePermissions(), - permissions -> { - PluginCall savedPermissionCall = bridge.getPermissionCall(handle.getId()); - - if (bridge.validatePermissions(this, savedPermissionCall, permissions)) { - checkPermissions(savedPermissionCall); + void initializeActivityLaunchers() { + List pluginClassMethods = new ArrayList<>(); + for ( + Class pluginCursor = getClass(); + !pluginCursor.getName().equals(Object.class.getName()); + pluginCursor = pluginCursor.getSuperclass() + ) { + pluginClassMethods.addAll(Arrays.asList(pluginCursor.getDeclaredMethods())); + } - if (!savedPermissionCall.isReleased() && !savedPermissionCall.isSaved()) { - savedPermissionCall.release(bridge); - } - } - } + for (final Method method : pluginClassMethods) { + if (method.isAnnotationPresent(ActivityCallback.class)) { + // register callbacks annotated with ActivityCallback for activity results + activityLaunchers.put( + method.getName(), + bridge + .getActivity() + .registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + result -> triggerActivityCallback(method, result) + ) ); + } else if (method.isAnnotationPresent(PermissionCallback.class)) { + // register callbacks annotated with PermissionCallback for permission results + permissionLaunchers.put( + method.getName(), + bridge + .getActivity() + .registerForActivityResult( + new ActivityResultContracts.RequestMultiplePermissions(), + permissions -> triggerPermissionCallback(method, permissions) + ) + ); + } + } + } - for (final Method method : getClass().getDeclaredMethods()) { - if (method.isAnnotationPresent(PluginMethod.class)) { - PluginMethod pluginAnnotation = method.getAnnotation(PluginMethod.class); - if (pluginAnnotation == null) { - continue; - } - - // get the defined permission callback, skip if default (empty string) - String permResponseMethodName = pluginAnnotation.permissionCallback(); - if (permResponseMethodName.isEmpty()) { - continue; - } + private void triggerPermissionCallback(Method method, Map permissionResultMap) { + PluginCall savedCall = bridge.getPermissionCall(handle.getId()); - try { - Method permResponseMethod = getClass().getDeclaredMethod(permResponseMethodName, PluginCall.class); - - if (permResponseMethod != null) { - permissionLaunchers.put( - method.getName(), - bridge - .getActivity() - .registerForActivityResult( - new ActivityResultContracts.RequestMultiplePermissions(), - permissions -> { - PluginCall savedPermissionCall = bridge.getPermissionCall(handle.getId()); - - if (bridge.validatePermissions(this, savedPermissionCall, permissions)) { - // handle request permissions call - try { - permResponseMethod.setAccessible(true); - permResponseMethod.invoke(this, savedPermissionCall); - } catch (IllegalAccessException | InvocationTargetException e) { - e.printStackTrace(); - } - - if (!savedPermissionCall.isReleased() && !savedPermissionCall.isSaved()) { - savedPermissionCall.release(bridge); - } - } - } - ) - ); - } - } catch (NoSuchMethodException e) { - Logger.error( - String.format( - "No method found by the name %s to register as a permission handler. " + - "Please check that it exists and has the correct signature: (PluginCall)", - permResponseMethodName - ) - ); + // validate permissions and invoke the permission result callback + if (bridge.validatePermissions(this, savedCall, permissionResultMap)) { + try { + method.setAccessible(true); + method.invoke(this, savedCall); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } - // if the provided method name is not a valid permission handling method, default to base method - permissionLaunchers.put(method.getName(), basePermissionLauncher); - } + if (!savedCall.isReleased() && !savedCall.isSaved()) { + savedCall.release(bridge); } } } + private void triggerActivityCallback(Method method, ActivityResult result) { + PluginCall savedCall = bridge.getSavedCall(lastPluginCallId); + if (savedCall == null) { + savedCall = bridge.getPluginCallForLastActivity(); + } + + // invoke the activity result callback + try { + method.setAccessible(true); + method.invoke(this, savedCall, result); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + + if (!savedCall.isReleased() && !savedCall.isSaved()) { + savedCall.release(bridge); + } + } + + /** + * Start activity for result with the provided Intent and resolve with the provided callback method name. + *

+ * If there is no registered activity callback for the method name passed in, the call will + * be rejected. Make sure a valid activity result callback method is registered using the + * {@link ActivityCallback} annotation. + * + * @param call the plugin call + * @param intent the intent used to start an activity + * @param callbackName the name of the callback to run when the launched activity is finished + * @since 3.0.0 + */ + public void startActivityForResult(PluginCall call, Intent intent, String callbackName) { + ActivityResultLauncher activityResultLauncher = getActivityLauncherOrReject(call, callbackName); + if (activityResultLauncher == null) { + // return when null since call was rejected in getLauncherOrReject + return; + } + + lastPluginCallId = call.getCallbackId(); + bridge.saveCall(call); + activityResultLauncher.launch(intent); + } + + private void permissionActivityResult(PluginCall call, String[] permissionStrings, String callbackName) { + ActivityResultLauncher permissionResultLauncher = getPermissionLauncherOrReject(call, callbackName); + if (permissionResultLauncher == null) { + // return when null since call was rejected in getLauncherOrReject + return; + } + + bridge.savePermissionCall(call); + permissionResultLauncher.launch(permissionStrings); + } + /** * Get the main {@link Context} for the current Activity (your app) * @return the Context for the current activity @@ -387,19 +422,13 @@ public boolean hasRequiredPermissions() { * * If there is no registered permission callback for the PluginCall passed in, the call will * be rejected. Make sure a valid permission callback method is registered using the - * {@link PluginMethod#permissionCallback()} annotation. + * {@link PermissionCallback} annotation. * * @since 3.0.0 * @param call the plugin call + * @param callbackName the name of the callback to run when the permission request is complete */ - protected void requestAllPermissions(@NonNull PluginCall call) { - String callMethodName = call.getMethodName(); - ActivityResultLauncher activityResultLauncher = getLauncherOrReject(call, callMethodName); - if (activityResultLauncher == null) { - // return when null since call was rejected in getLauncherOrReject - return; - } - + protected void requestAllPermissions(@NonNull PluginCall call, @NonNull String callbackName) { CapacitorPlugin annotation = handle.getPluginAnnotation(); if (annotation != null) { HashSet perms = new HashSet<>(); @@ -407,8 +436,7 @@ protected void requestAllPermissions(@NonNull PluginCall call) { perms.addAll(Arrays.asList(perm.strings())); } - bridge.savePermissionCall(call); - activityResultLauncher.launch(perms.toArray(new String[0])); + permissionActivityResult(call, perms.toArray(new String[0]), callbackName); } } @@ -417,13 +445,14 @@ protected void requestAllPermissions(@NonNull PluginCall call) { * * If there is no registered permission callback for the PluginCall passed in, the call will * be rejected. Make sure a valid permission callback method is registered using the - * {@link PluginMethod#permissionCallback()} annotation. + * {@link PermissionCallback} annotation. * * @param alias an alias defined on the plugin - * @param call the plugin call involved in originating the request + * @param call the plugin call involved in originating the request + * @param callbackName the name of the callback to run when the permission request is complete */ - protected void requestPermissionForAlias(@NonNull String alias, @NonNull PluginCall call) { - requestPermissionForAliases(new String[] { alias }, call); + protected void requestPermissionForAlias(@NonNull String alias, @NonNull PluginCall call, @NonNull String callbackName) { + requestPermissionForAliases(new String[] { alias }, call, callbackName); } /** @@ -431,42 +460,22 @@ protected void requestPermissionForAlias(@NonNull String alias, @NonNull PluginC * * If there is no registered permission callback for the PluginCall passed in, the call will * be rejected. Make sure a valid permission callback method is registered using the - * {@link PluginMethod#permissionCallback()} annotation. + * {@link PermissionCallback} annotation. * * @param aliases a set of aliases defined on the plugin - * @param call the plugin call involved in originating the request + * @param call the plugin call involved in originating the request + * @param callbackName the name of the callback to run when the permission request is complete */ - protected void requestPermissionForAliases(@NonNull String[] aliases, @NonNull PluginCall call) { - String callMethodName = call.getMethodName(); - ActivityResultLauncher activityResultLauncher = getLauncherOrReject(call, callMethodName); - if (activityResultLauncher == null) { - // return when null since call was rejected in getLauncherOrReject - return; - } - + protected void requestPermissionForAliases(@NonNull String[] aliases, @NonNull PluginCall call, @NonNull String callbackName) { if (aliases.length == 0) { Logger.error("No permission alias was provided"); return; } - requestPermissionForAliases(aliases, call, activityResultLauncher); - } - - /** - * Request permissions using aliases defined on the plugin with a provided activityResultLauncher. - * Plugin authors should use {@link #requestPermissionForAliases(String[], PluginCall)} with - * a registered callback method for typical permission request use. - */ - private void requestPermissionForAliases( - @NonNull String[] aliases, - @NonNull PluginCall call, - ActivityResultLauncher activityResultLauncher - ) { String[] permissions = getPermissionStringsForAliases(aliases); if (permissions.length > 0) { - bridge.savePermissionCall(call); - activityResultLauncher.launch(permissions); + permissionActivityResult(call, permissions, callbackName); } } @@ -490,43 +499,63 @@ private String[] getPermissionStringsForAliases(@NonNull String[] aliases) { } /** - * Gets the permission launcher associated with the calling methodName, or rejects the call if + * Gets the activity launcher associated with the calling methodName, or rejects the call if * no registered launcher exists * - * @param call the plugin call - * @param methodName the name of the plugin method requesting a permission + * @param call the plugin call + * @param methodName the name of the activity callback method * @return a launcher, or null if none found */ - private @Nullable ActivityResultLauncher getLauncherOrReject(PluginCall call, String methodName) { - ActivityResultLauncher activityResultLauncher = permissionLaunchers.get(methodName); + private @Nullable ActivityResultLauncher getActivityLauncherOrReject(PluginCall call, String methodName) { + ActivityResultLauncher activityLauncher = activityLaunchers.get(methodName); - // if there is no registered result launcher but the method is the default requestPermissions - // method, associate the base permission launcher to make sure states are returned - if (activityResultLauncher == null && methodName.equals("requestPermissions")) { - activityResultLauncher = basePermissionLauncher; + // if there is no registered launcher, reject the call with an error and return null + if (activityLauncher == null) { + String registerError = + "There is no ActivityCallback method registered for the name: %s. " + + "Please define a callback method annotated with @ActivityCallback " + + "that receives arguments: (PluginCall, ActivityResult)"; + registerError = String.format(Locale.US, registerError, methodName); + Logger.error(registerError); + call.reject(registerError); + return null; } + return activityLauncher; + } + + /** + * Gets the permission launcher associated with the calling methodName, or rejects the call if + * no registered launcher exists + * + * @param call the plugin call + * @param methodName the name of the permission callback method + * @return a launcher, or null if none found + */ + private @Nullable ActivityResultLauncher getPermissionLauncherOrReject(PluginCall call, String methodName) { + ActivityResultLauncher permissionLauncher = permissionLaunchers.get(methodName); + // if there is no registered launcher, reject the call with an error and return null - if (activityResultLauncher == null) { + if (permissionLauncher == null) { String registerError = - "There is no permission callback method registered for the plugin method %s. " + - "Please define a permissionCallback method name in the annotation and provide a " + - "method that has the correct signature: (PluginCall)"; + "There is no PermissionCallback method registered for the name: %s. " + + "Please define a callback method annotated with @PermissionCallback " + + "that receives arguments: (PluginCall)"; registerError = String.format(Locale.US, registerError, methodName); Logger.error(registerError); call.reject(registerError); return null; } - return activityResultLauncher; + return permissionLauncher; } /** * Helper for requesting specific permissions - * @deprecated use {@link #requestPermissions(PluginCall)} in conjunction with @CapacitorPlugin * * @param permissions the set of permissions to request * @param requestCode the requestCode to use to associate the result with the plugin + * @deprecated use {@link #requestPermissions(PluginCall)} in conjunction with @CapacitorPlugin */ @Deprecated public void pluginRequestPermissions(String[] permissions, int requestCode) { @@ -535,7 +564,8 @@ public void pluginRequestPermissions(String[] permissions, int requestCode) { /** * Request all of the specified permissions in the CapacitorPlugin annotation (if any) - * @deprecated use {@link #requestAllPermissions(PluginCall)} in conjunction with @CapacitorPlugin + * + * @deprecated use {@link #requestAllPermissions(PluginCall, String)} in conjunction with @CapacitorPlugin */ @Deprecated public void pluginRequestAllPermissions() { @@ -545,10 +575,10 @@ public void pluginRequestAllPermissions() { /** * Helper for requesting a specific permission - * @deprecated use {@link #requestPermissionForAlias(String, PluginCall)} in conjunction with @CapacitorPlugin * - * @param permission the permission to request + * @param permission the permission to request * @param requestCode the requestCode to use to associate the result with the plugin + * @deprecated use {@link #requestPermissionForAlias(String, PluginCall, String)} in conjunction with @CapacitorPlugin */ @Deprecated public void pluginRequestPermission(String permission, int requestCode) { @@ -713,6 +743,7 @@ public void removeAllListeners(PluginCall call) { * @since 3.0.0 */ @PluginMethod + @PermissionCallback public void checkPermissions(PluginCall pluginCall) { Map permissionsResult = getPermissionStates(); @@ -732,9 +763,9 @@ public void checkPermissions(PluginCall pluginCall) { /** * Exported plugin call to request all permissions for this plugin. * To manually request permissions within a plugin use: - * {@link #requestAllPermissions(PluginCall)}, or - * {@link #requestPermissionForAlias(String, PluginCall)}, or - * {@link #requestPermissionForAliases(String[], PluginCall)} + * {@link #requestAllPermissions(PluginCall, String)}, or + * {@link #requestPermissionForAlias(String, PluginCall, String)}, or + * {@link #requestPermissionForAliases(String[], PluginCall, String)} * * @param call the plugin call */ @@ -799,7 +830,7 @@ public void requestPermissions(PluginCall call) { if (permAliases != null && permAliases.length > 0) { // request permissions using provided aliases or all defined on the plugin - requestPermissionForAliases(permAliases, call, basePermissionLauncher); + requestPermissionForAliases(permAliases, call, "checkPermissions"); } else if (!autoGrantPerms.isEmpty()) { // if the plugin only has auto-grant permissions, return all as GRANTED JSObject permissionsResults = new JSObject(); @@ -877,17 +908,9 @@ protected void restoreState(Bundle state) {} /** * Handle activity result, should be overridden by each plugin - * @param lastPluginCall - * @param requestCode - * @param resultCode - * @param data - */ - protected void handleOnActivityResult(PluginCall lastPluginCall, int requestCode, int resultCode, Intent data) {} - - /** - * Handle activity result, should be overridden by each plugin - * @deprecated use {@link #handleOnActivityResult(PluginCall, int, int, Intent)} in - * conjunction with @CapacitorPlugin + * + * @deprecated provide a callback method using the {@link ActivityCallback} annotation and use + * the {@link #startActivityForResult(PluginCall, Intent, String)} method * * @param requestCode * @param resultCode @@ -959,6 +982,7 @@ public Boolean shouldOverrideLoad(Uri url) { * @param intent * @param resultCode */ + @Deprecated protected void startActivityForResult(PluginCall call, Intent intent, int resultCode) { bridge.startActivityForPluginWithResult(call, intent, resultCode); } diff --git a/android/capacitor/src/main/java/com/getcapacitor/PluginHandle.java b/android/capacitor/src/main/java/com/getcapacitor/PluginHandle.java index 7c6d80e901..b08cbad54d 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/PluginHandle.java +++ b/android/capacitor/src/main/java/com/getcapacitor/PluginHandle.java @@ -93,7 +93,7 @@ public Plugin load() throws PluginLoadException { this.instance.setPluginHandle(this); this.instance.setBridge(this.bridge); this.instance.load(); - this.instance.initializePermissionLaunchers(); + this.instance.initializeActivityLaunchers(); return this.instance; } catch (InstantiationException | IllegalAccessException ex) { throw new PluginLoadException("Unable to load plugin instance. Ensure plugin is publicly accessible"); diff --git a/android/capacitor/src/main/java/com/getcapacitor/PluginMethod.java b/android/capacitor/src/main/java/com/getcapacitor/PluginMethod.java index ed4ccbc95a..856630431a 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/PluginMethod.java +++ b/android/capacitor/src/main/java/com/getcapacitor/PluginMethod.java @@ -12,10 +12,4 @@ String RETURN_NONE = "none"; String returnType() default RETURN_PROMISE; - - /** - * The name of a method that should be called on the result of a permission request. This method - * should be defined in the class with the parameters (PluginCall). - */ - String permissionCallback() default ""; } diff --git a/android/capacitor/src/main/java/com/getcapacitor/annotation/ActivityCallback.java b/android/capacitor/src/main/java/com/getcapacitor/annotation/ActivityCallback.java new file mode 100644 index 0000000000..a158145d7c --- /dev/null +++ b/android/capacitor/src/main/java/com/getcapacitor/annotation/ActivityCallback.java @@ -0,0 +1,11 @@ +package com.getcapacitor.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ActivityCallback { +} diff --git a/android/capacitor/src/main/java/com/getcapacitor/annotation/CapacitorPlugin.java b/android/capacitor/src/main/java/com/getcapacitor/annotation/CapacitorPlugin.java index 235a281021..80294e0d18 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/annotation/CapacitorPlugin.java +++ b/android/capacitor/src/main/java/com/getcapacitor/annotation/CapacitorPlugin.java @@ -9,20 +9,14 @@ @Retention(RetentionPolicy.RUNTIME) public @interface CapacitorPlugin { /** - * Request codes this plugin uses and responds to, in order to tie - * Android events back the plugin to handle + * A custom name for the plugin, otherwise uses the + * simple class name. */ - int[] requestCodes() default {}; + String name() default ""; /** * Permissions this plugin needs, in order to make permission requests * easy if the plugin only needs basic permission prompting */ Permission[] permissions() default {}; - - /** - * A custom name for the plugin, otherwise uses the - * simple class name. - */ - String name() default ""; } diff --git a/android/capacitor/src/main/java/com/getcapacitor/annotation/PermissionCallback.java b/android/capacitor/src/main/java/com/getcapacitor/annotation/PermissionCallback.java new file mode 100644 index 0000000000..d4ca099219 --- /dev/null +++ b/android/capacitor/src/main/java/com/getcapacitor/annotation/PermissionCallback.java @@ -0,0 +1,11 @@ +package com.getcapacitor.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface PermissionCallback { +}