'Howto getExtras from a local broadcast Intent in react-native

in my React-Native opened project, I want to receive the data (extra text) sent by another local service app named "scanservice" on its intent output (broadcast) on a Action named "scanservice.data" , and I do not know how to start & write that : someone can help me please? I have tried without success HeadlessJs, Linking solutions.



Solution 1:[1]

I put some more info I got and I please ask for some corrections since I am null in Java writting :

I want to make a native Android module (in java) (as described on RN site : https://reactnative.dev/docs/native-modules-android) to catch the text ('extra_text') sent by an intent of another app, named "manuf".

The class 'scan_intent.java' I wrote here has many mistakes (with "//error":

package com.intent_scan;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import org.w3c.dom.Text;

public class ScanIntent extends ReactContextBaseJavaModule {
    //constructor
    // normaly : "public class ScanIntent extends BroadcastReceiver" : how to add this ?
    public ScanIntent(ReactApplicationContext reactContext) {
        super(reactContext);
    }
 @Override
public String getName() {
   return "ScanIntent";
}
    //Custom function that we are going to export to JS
    @ReactMethod
    public void onReceive(Context context, Intent intent, String extra_text){
        if  ("manuf.scanservice.data".equals(intent.getAction()))
        {
        getReactApplicationContext().registerReceiver //error on registerR...
        try {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                extra_text = extras.getString("text"); //error : this value will be returned ?
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

        }

}}

thank you !

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Prx