Last active
July 20, 2018 02:27
-
-
Save hemantasapkota/1a70a13e305104c3911e50a47640a1d0 to your computer and use it in GitHub Desktop.
CommandPackage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CommanderModule extends ReactContextBaseJavaModule { | |
public CommanderModule(ReactApplicationContext reactContext) { | |
super(reactContext); | |
} | |
@ReactMethod | |
public void postCommand(ReadableMap config, Callback successCallback, Callback cancelCallback) { | |
try { | |
byte[] data = Olclient.postCommand(config.getString("command")); | |
String dat = new String(data); | |
successCallback.invoke(dat); | |
} catch (Exception e) { | |
cancelCallback.invoke(e.getMessage()); | |
} | |
} | |
@Override | |
public String getName() { | |
return "Commander"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CommandPackage implements ReactPackage { | |
@Override | |
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { | |
List<NativeModule> modules = new ArrayList<NativeModule>(); | |
modules.add(new CommanderModule(reactContext)); | |
return modules; | |
} | |
@Override | |
public List<Class<? extends JavaScriptModule>> createJSModules() { | |
return Collections.emptyList(); | |
} | |
@Override | |
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | |
return Collections.emptyList(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainApplication extends Application implements ReactApplication { | |
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { | |
@Override | |
public boolean getUseDeveloperSupport() { | |
return BuildConfig.DEBUG; | |
} | |
@Override | |
protected List<ReactPackage> getPackages() { | |
return Arrays.<ReactPackage>asList( | |
new MainReactPackage(), | |
new CommandPackage() | |
); | |
} | |
}; | |
@Override | |
public ReactNativeHost getReactNativeHost() { | |
return mReactNativeHost; | |
} | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
// React Native | |
SoLoader.init(this, /* native exopackage */ false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment