Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ionic 5 + Capacitor - How to implement external broadcaster ? #72

Open
givemesumthing opened this issue May 28, 2024 · 3 comments
Open

Comments

@givemesumthing
Copy link

givemesumthing commented May 28, 2024

How to implement external broadcaster , i.e. send data from one app to another ?

I have tried :-

From App 1 :-

        let options1 = {
          filterActions: ['com.example.APPS_TOKEN'],
          extras: {
            'param1': 'abc',
            'param2': 'xyz'
          }
        };
      if (this.platform.is('android') && this.platform.is('capacitor')) {
        var isGlobal = true
        this.broadcaster.fireNativeEvent("APPS_TOKEN", isGlobal, options1).then(res => {
          console.log("event fired!");
        })

And in App 2 :-

 let listener = function( e ) {
      console.log( "APPS_TOKEN received! userInfo: " + JSON.stringify(e)  );
    }
    
    this.broadcaster.addEventListener( "APPS_TOKEN").subscribe( listener );
    

But here data is not being sent to second app .

Is there a sample or documentation for it ?
Also, do we need to set up anything in AndroidManifest.xml file ?

@givemesumthing givemesumthing changed the title How to implement external broadcaster ? Ionic 5 + Capacitor - How to implement external broadcaster ? May 28, 2024
@bsorrentino
Copy link
Owner

bsorrentino commented May 29, 2024

Hi @givemesumthing

This plugin has been through to work for in-process-communication, that is, in a single app. Obviously it can be useful also in your case but it must be used on top of an inter-process-communication(IPC) protocol.

here is an article that could help you

@givemesumthing
Copy link
Author

Hi @bsorrentino,
For my specific requirement, I only need to broadcast to an app that remains open in the background, without necessitating its foreground activation. While the provided code enables broadcasting from one foreground app, I'm encountering difficulty in receiving it within app 2 using this plugin. Although I successfully registered the receiver in MainActivity, how can I effectively relay this information from the Android app's main activity to the plugin's this.broadcaster.addEventListener ?

@bsorrentino
Copy link
Owner

bsorrentino commented Jun 12, 2024

Hi @givemesumthing

I assume that you have already solved issue concerning inter-process-communication and you have tested that the message from external broker arrive correctly in your background app

Anyway I never tested the plugin in such condition. As you said, the plugin has been developed to be used in foreground app.

I haven't idea what happens in Cordova/Capacitor runtime when app goes in background, so we need to understand first if, in background mode, messages are correctly delivered and after that, investigate specifically on your use case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants