title: Triggering react-native events from widget - android
body: <p>I've made an app using react-native, however I need to trigger a react event from an android widget. This is currently my setup:</p>
  
  <pre><code>public class IsHetAlBierTijdWidget extends AppWidgetProvider {
  
      static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                                  int appWidgetId) {
  
          CharSequence widgetText = context.getString(R.string.app_name);
          // Construct the RemoteViews object
          RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.is_het_al_bier_tijd_widget);
  
          // Instruct the widget manager to update the widget
          appWidgetManager.updateAppWidget(appWidgetId, views);
      }
  
      @Override
      public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
          // There may be multiple widgets active, so update all of them
          for (int appWidgetId : appWidgetIds) {
              updateAppWidget(context, appWidgetManager, appWidgetId);
              sendEventToReactApp(context);
          }
      }
  
      @Override
      public void onEnabled(Context context) {
          // Enter relevant functionality for when the first widget is created
      }
  
      @Override
      public void onDisabled(Context context) {
          // Enter relevant functionality for when the last widget is disabled
      }
  
      public void sendEventToReactApp(Context context) {
          WritableMap event = Arguments.createMap();
          event.putString("message", "MyMessage");
          ReactApplicationContext reactApplicationContext = new ReactApplicationContext(context);
          MSREventBridgeModule msrEventBridgeModule = new MSREventBridgeModule(reactApplicationContext);
          msrEventBridgeModule.emitEvent("Widget_Update",event);
      }
  }
  </code></pre>
  
  <p>react code:</p>
  
  <pre><code>class Home extends Component {
  
      constructor(){
          super();
          this.onWidgetUpdate.bind(this);
      }
  
      onWidgetUpdate(){
          console.log("widget update...");
      }
  
      componentWillMount() {
          this.props.fetchBierTijd()
          DeviceEventEmitter.addListener('Widget_Update', this.onWidgetUpdate);
      }
  
      componentWillUnmount() {
          DeviceEventEmitter.removeListener('Widget_Update', this.onWidgetUpdate);
      }
  
      render() {
          return (
              &lt;View style={{flex: 1, justifyContent:'center', alignItems:'center'}}&gt;
                  &lt;Countdown
                      style={{marginTop: 80}} fontSize="40"
                      isBiertijd={this.props.isBierTijd}
                      timeLeft={this.props.timeLeft}
                  /&gt;
              &lt;/View&gt;
          )
      }
  }
  
  const mapStateToPros = state =&gt; ({
      fetching: state.bierTijd.fetching,
      isBierTijd: state.bierTijd.isBierTijd,
      nextBierTijd: state.bierTijd.next,
      timeLeft: moment(state.bierTijd.next).diff(moment())
  })
  
  
  const mapDispatchToProps = dispatch =&gt; {
      return bindActionCreators({...bierTijdActions,}, dispatch)
  }
  
  export default connect(mapStateToPros, mapDispatchToProps)(Home)
  </code></pre>
  
  <p>Is it possible to do this, or does the event need to be triggered from the main activity? a good explanation of communication from native to react native would also be appreciated.</p>