title: How to call native android module from react native JS
body: <p>I am facing issue in calling my java class methods (android native code) from JS. 
  I have already followed <a href="https://facebook.github.io/react-native/docs/native-modules-android.html" rel="nofollow noreferrer">https://facebook.github.io/react-native/docs/native-modules-android.html</a> but its not working. Please find below the issues which I am facing.</p>
  
  <ol>
  <li>Where we should export android module, I have done it in index.js</li>
  </ol>
  
  <blockquote>
  <pre><code>import {NativeModules} from 'react-native';
  
  const { ScannerInteractor } = NativeModules;
  
  export default ScannerInteractor;
  </code></pre>
  </blockquote>
  
  <p>or </p>
  
  <blockquote>
  <pre><code>import {NativeModules} from 'react-native';
  module.exports = NativeModules.ScannerInteractor;
  </code></pre>
  </blockquote>
  
  <ol start="2">
  <li>In a javascript class where I want to call this method how should I import my class, I have written following code. Does it matter if index.js are at same level as of my javascript class?</li>
  </ol>
  
  <blockquote>
    <p>import ScannerInteractor from "./ScannerInteractor"</p>
  </blockquote>
  
  <ol start="3">
  <li>I have created member methods then how to call them? As per example, it need to be call as static method call.</li>
  </ol>
  
  <blockquote>
  <pre><code>   ScannerInteractor.startScan(this, null, null);
  </code></pre>
  </blockquote>
  
  <ol start="4">
  <li>How to pass context variable from JS, will passing 'this' parameter will work?</li>
  </ol>
  
  <p>I am not getting any error or log messages in the logcat but method is also not getting triggered.</p>
  
  <p>NativeModule class</p>
  
  <pre><code>import com.facebook.react.ReactPackage; 
  import com.facebook.react.bridge.NativeModule; 
  import com.facebook.react.bridge.ReactApplicationContext; 
  import com.facebook.react.uimanager.ViewManager;
  
  import java.util.ArrayList; 
  import java.util.Collections; 
  import java.util.List; 
  import com.kohl.scan.common.ScannerInteractor;
  
  public class ModuleInjector implements ReactPackage {
  
  @Override   
  public List&lt;ViewManager&gt; createViewManagers(ReactApplicationContext reactContext) {
          return Collections.emptyList();
     }
  
        @Override   public List&lt;NativeModule&gt; createNativeModules(
                                    ReactApplicationContext reactContext) {
          List&lt;NativeModule&gt; modules = new ArrayList&lt;&gt;();
  
          modules.add(new ScannerInteractor(reactContext));
  
          return modules;
     }
  
   }
  </code></pre>
  
  <p>ApplicationClass</p>
  
  <pre><code>import com.facebook.react.ReactPackage;
  
  import java.util.Arrays;
  import java.util.List;
  
  import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
  import com.reactnativenavigation.NavigationApplication;
  import com.oblador.vectoricons.VectorIconsPackage;
  import com.rfpproject.ModuleInjector;
  
  public class MainApplication extends NavigationApplication {
  
    @Override
    public boolean isDebug() {
      // Make sure you are using BuildConfig from your own application
      return BuildConfig.DEBUG;
    }
  
    protected List&lt;ReactPackage&gt; getPackages() {
      // Add additional packages you require here
      // No need to add RnnPackage and MainReactPackage
      return Arrays.&lt;ReactPackage&gt;asList(
      // eg. new VectorIconsPackage()
              new ReactNativeConfigPackage(),
              new VectorIconsPackage(),
              new ModuleInjector()
      );
    }
  
    @Override
    public String getJSMainModuleName() {
      return "index";
    }
  
    @Override
    public List&lt;ReactPackage&gt; createAdditionalReactPackages() {
      return getPackages();
    }
  }
  </code></pre>
  
  <p>I am calling it from JS script as mentioned below:</p>
  
  <pre><code>  onClick1(){
      ScannerInteractor.startScan(this, null, null);
      //alert('cllllll');
    }
  </code></pre>