use of com.getcapacitor.annotation.PermissionCallback in project capacitor by ionic-team.
the class Plugin method initializeActivityLaunchers.
/**
* Registers activity result launchers defined on plugins, used for permission requests and
* activities started for result.
*/
void initializeActivityLaunchers() {
List<Method> pluginClassMethods = new ArrayList<>();
for (Class<?> pluginCursor = getClass(); !pluginCursor.getName().equals(Object.class.getName()); pluginCursor = pluginCursor.getSuperclass()) {
pluginClassMethods.addAll(Arrays.asList(pluginCursor.getDeclaredMethods()));
}
for (final Method method : pluginClassMethods) {
if (method.isAnnotationPresent(ActivityCallback.class)) {
// register callbacks annotated with ActivityCallback for activity results
ActivityResultLauncher<Intent> launcher = bridge.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> triggerActivityCallback(method, result));
activityLaunchers.put(method.getName(), launcher);
} else if (method.isAnnotationPresent(PermissionCallback.class)) {
// register callbacks annotated with PermissionCallback for permission results
ActivityResultLauncher<String[]> launcher = bridge.registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), permissions -> triggerPermissionCallback(method, permissions));
permissionLaunchers.put(method.getName(), launcher);
}
}
}
Aggregations