Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Add support for global broadcasts #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Add support for global broadcasts #1

wants to merge 5 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 3, 2018

Add sendGlobalBroadcast() which allows different cordova web app and native android application to communicate using intents.

mtabReceiver = MTabBroadcastReceiver()
val mtabIntent = IntentFilter(“INTENT_NAME”) // must match or else it won’t be received
mtabIntent.addAction(“INTENT_ACTION”) // must match or else it won’t be received
registerReceiver(mtabReceiver, mtabIntent)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to use something other than MTab for your examples :)

@@ -60,15 +60,17 @@ else if( data instanceof JSONObject ) {
* @param filter
*/
protected void registerReceiver(android.content.BroadcastReceiver receiver, android.content.IntentFilter filter) {
LocalBroadcastManager.getInstance(super.webView.getContext()).registerReceiver(receiver,filter);
// LocalBroadcastManager.getInstance(super.webView.getContext()).registerReceiver(receiver,filter);
this.webView.getContext().registerReceiver(receiver, filter);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this impact the local events' behavior? If not, I recommend just removing the commented-out lines

else if (action.equals("sendGlobalBroadcast")) {
final String eventName = args.getString(0);
if( eventName==null || eventName.isEmpty() ) {
callbackContext.error(EVENTNAME_ERROR);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make sure the style matches the rest of the existing code (white-space inside the parens, and such)

}

Log.w("eventName: ", eventName);
Log.w("actionName: ", actionName);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove warnings or convert to debug messages


this.webView.getContext().sendBroadcast(intent);
return intent.toString();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the benefit/value in returning intent.toString()? Just noticing that fireNativeEvent() doesn't return anything

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that was me debugging.

}
final String actionName = args.getString(1);
final JSONObject userData = args.getJSONObject(2);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to do further checks on these values, like we did for eventName?

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

Successfully merging this pull request may close these issues.

2 participants