Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从非React类发送React应用程序上下文?_Android_Ios_Reactjs_React Native_Bridge - Fatal编程技术网

Android 如何从非React类发送React应用程序上下文?

Android 如何从非React类发送React应用程序上下文?,android,ios,reactjs,react-native,bridge,Android,Ios,Reactjs,React Native,Bridge,我需要更新状态更改,比如android和react本机类之间的事件 public class MessagingService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { Log.d(TAG, "Push Message Received "); buil

我需要更新状态更改,比如android和react本机类之间的事件

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);
      }
    }
当类扩展到FBMessingService时,如何创建
ReactApplicationContext
构造函数

FBMessagingHelper notificationHelper = new FBMessagingHelper(this.getApplication());
// Getting Error as a parameter is not react app context
我需要更新视频进度中的
状态

  • 通过
    React Native
    启动/停止视频时,更新到
    Android
  • 通过
    Android
    启动/停止视频时,更新到
    React Native
  • 创建的本机模块:

        public class FBMessagingPackage implements ReactPackage{
        @Override
          public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
            List<NativeModule> modules = new ArrayList<>();
            modules.add(new FBMessagingHelper(reactContext));
            modules.add((NativeModule) new MessagingService(reactContext));
            // Error: cannot be cast to nativeModule
            return modules;
          }
            ...
            ...
        }
    
    公共类FBMessagingPackage实现了ReactPackage{
    @凌驾
    公共列表createNativeModules(ReactApplicationContext reactContext){
    列表模块=新的ArrayList();
    添加(新的FBMessagingHelper(reactContext));
    modules.add((NativeModule)new MessagingService(reactContext));
    //错误:无法转换为nativeModule
    返回模块;
    }
    ...
    ...
    }
    
    我不知怎么解决了这个问题。我们无法在
    FirebaseMessagingService
    上扩展
    ReactApplicationContext
    。即使应用程序未运行且我们无法控制添加react上下文,也会调用此服务

    因此,我创建了一个单独的模块并添加了监听器,这些监听器将更新事件数据到FBMessagingHelper类

    public class FBMessagingPackage implements ReactPackage{
        @Override
          public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
            List<NativeModule> modules = new ArrayList<>();
            modules.add(new VideoModule(reactContext));
            return modules;
          }
        }
    
    public class FBMessagingPackage implements ReactPackage{
        @Override
          public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
            List<NativeModule> modules = new ArrayList<>();
            modules.add(new VideoModule(reactContext));
            return modules;
          }
        }
    
    public class VideoModule extends ReactContextBaseJavaModule {
       private ReactApplicationContext mContext;
    
      public VideoModule(ReactApplicationContext reactContext) { // Added into Native Modules
         mContext = applicationContext;
      }
    
    @ReactMethod
        public void onVideoProgress(Bolean status){
            FBMessagingHelper.IN_VIDEO_PROGRESS = status 
            // Store it to public static variable of FBMessagingHelper
        }
    
     @Nonnull
     @Override
        public String getName() {
            return "VideoModule";
        }
    
    
    }