Recently in looking at react-native, the internal implementation is very interested in, and I wrote the module registered in, and in JS call, very curious how his method is exposed to JS, see the source of Basejavamodule, inside there is how to expose the method.
@Overridepublic final map<string, nativemethod> getmethods () { map <String, NativeMethod> methods = new HashMap<String, NativeMethod> () ; method[] targetmethods = getclass (). Getdeclaredmethods (); for (int i = 0; i < targetmethods.length; i++) { method targetmethod = targetmethods[i]; //find a way to @reactmethod annotations if (Targetmethod.getannotation (reactmethod.class) != null) { string methodname = targetmethod.getname (); if (Methods.containskey (methodName)) { // We do not support method overloading since js sees a function as an&Nbsp;object regardless // of number of params. throw new illegalargumentexception ( "java module " + GetName () + " method name already registered: " + methodname); } methods.put (MethodName, new javamethod (Targetmethod)); } } return methods ;}
React-native how the Android Java module exposes its own method to JS