Is there any way in ionic to listen to android custom broadcast message?

I have found one non-angular implementation here : https://www.npmjs.com/package/cordova-plugin-broadcaster, But that’s not working.

Here is my code inside app.js’s $ionicPlatform.ready function :

if (window.broadcaster) {
        window.broadcaster.addEventListener( "CUSTOM_EVENT_NAME_BROADCASTED_FROM_NATIVE_LAYER", function( e ) {
                console.log( "Event received! userInfo: " + JSON.stringify(e)  );
        });            
} else {
        console.log('windown.broadcaster not available');
}

It’s not invoking the else block, and the registered callback-block is not called also.

Any pointer would be helpful.

Thanks

  • Tushar

So far no reply from anyone. But eh good news is the problem is fixed.
It was an issue with another plugin that is the source of posting the broadcast. Now the above plugin works fine now with a minor fix for a potential crash.

If anyone is looking for listening to broadcast messages, the above plugin (https://www.npmjs.com/package/cordova-plugin-broadcaster) can be used. :smile:

Thanks

  • Tushar
1 Like