import android.app.Activity;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
public class AwesomeModule extends ReactContextBaseJavaModule {
public AwesomeModule(ReactApplicationContext reactContext) {
super(reactContext);
@Override
public String getName() {
return "AwesomeAndroid";
private static final String ERROR_NO_ACTIVITY = "E_NO_ACTIVITY";
private static final String ERROR_NO_ACTIVITY_MESSAGE = "Tried to do the something while not attached to an Activity";
@ReactMethod
public void doSomething(successCallback, errorCallback) {
final Activity activity = getCurrentActivity();
if (activity == null) {
errorCallback(ERROR_NO_ACTIVITY, ERROR_NO_ACTIVITY_MESSAGE);
return;
}
@ReactMethod
public void doSomethingRequiringWindow() {
// get access to current UI thread first
reactContext.getCurrentActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Window window = reactContext
.getCurrentActivity().getWindow();
View decorView = reactContext