Home / IOS Development / android – How do I send React Application context from non-responsive class?

android – How do I send React Application context from non-responsive class?



Do I need to update status changes such as event between android and respond native class?

public class MessagingService extends FirebaseMessagingService {
      @Override
      public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d(TAG, "Push Message Received ");
        buildLocalNotification(remoteMessage);
      }

      public void buildLocalNotification(RemoteMessage message) {
        ...
        FBMessagingHelper notificationHelper = new FBMessagingHelper(this.getApplication());
        notificationHelper.showNotification(bundle);
      }
    }

How can I make one ReactApplicationContext constructor as class extended to FBMessingService?

FBMessagingHelper notificationHelper = new FBMessagingHelper(this.getApplication());
// Getting Error as a parameter is not react app context

I need to update IN_VIDEO_PROGRESS status

  1. Update to Android when video starts / drop by React Native.
  2. Update to React Native when video starts / drop by Android.
public class FBMessagingHelper extends ReactContextBaseJavaModule {
  private ReactApplicationContext mContext;
  private static boolean IN_VIDEO_PROGRESS = false;

  public FBMessagingHelper(ReactApplicationContext reactContext) { // Added into Native Modules
     mContext = applicationContext;
  }

@ReactMethod
    public void onVideoProgress(Bolean status){
        // ==== on videoProgress ====
        IN_VIDEO_PROGRESS = status
    }

 @Nonnull
 @Override
    public String getName() {
        return "FBMessagingHelper";
    }

  public void showCustomNotification(Bundle bundle) {
    if (!IN_VIDEO_PROGRESS && bundle.getString("category").equals("VIDEO") {
       IN_VIDEO_PROGRESS = true;
       // start FullScreenNotificationActivity
    }
  }
}

Created native modules:

    public class FBMessagingPackage implements ReactPackage{
    @Override
      public List createNativeModules(ReactApplicationContext reactContext) {
        List modules = new ArrayList<>();
        modules.add(new FBMessagingHelper(reactContext));
        modules.add((NativeModule) new MessagingService(reactContext));
        // Error: cannot be cast to nativeModule
        return modules;
      }
        ...
        ...
    }


Source link