I am creating a plugin for Android on Ionic/Angular. I don't know a way to pass the value of a variable from an android application (QRData from BroadcastReceiver) to the code of my project (call.resolve(ret)). Now the QR-code is scanned in the application and its decryption is displayed in the console of the Android Studio. And I want to work with this qr-code in the code of the angular-project / ionic-application (for example, based on the decoding of the QR - display information on it on the screen). The ionic application works on a "Sunmi L2" phone with a built-in infrared QR-code reader, so I am writing the ionic plugin myself.
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;
@CapacitorPlugin(name = "ScannerQR")
public class ScannerQRPlugin extends Plugin {
BroadcastReceiver QRCODE_SUNMI = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Think of a way to pass 'call' to code; and so - everything works
String QRData = intent.getStringExtra("data");
Log.d("SCAN_QR", QRData);
// TODO Need a way to pass QRData to the Angular-project code
}
};
@PluginMethod
public void echo(PluginCall call) {
try {
getContext().unregisterReceiver(QRCODE_SUNMI);
} catch (Exception ex) {
Log.i("unregisterReceiver", "Ignore Disabling Receiver");
}
getContext().registerReceiver(QRCODE_SUNMI, new IntentFilter("com.sunmi.scanner.ACTION_DATA_CODE_RECEIVED"));
JSObject ret = new JSObject();
ret.put("value", "Any text from application to Angular-project");
call.resolve(ret);
}
}
Tell me how to do this?