-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for global broadcasts #1
base: master
Are you sure you want to change the base?
Conversation
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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); | ||
|
There was a problem hiding this comment.
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
?
Add
sendGlobalBroadcast()
which allows different cordova web app and native android application to communicate using intents.