[TIMOB-18146] Android: Cannot send Broadcast with data property defined in the intent
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2015-07-08T07:44:42.000+0000 |
Affected Version/s | Release 3.4.1, Release 4.0.0 |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Benjamin Hatfield |
Assignee | Ashraf Abu |
Created | 2014-12-06T00:51:39.000+0000 |
Updated | 2017-03-17T18:02:55.000+0000 |
Description
CAVEAT:
Cannot tell if this should work or not. Cannot find any official information in the Android docs. Stackoverflow and other topics say you can only send data through extras, which does work in this example.
REPRODUCTION:
Run the code below in the Genymotion emulator and click the "Send Broadcast" button.
RESULTS:
Broadcast is not sent.
OTHER INFO:
Comment out line #9 (data property) and rerun the test. Intent is sent and received.
var win = Ti.UI.createWindow();
var button = Ti.UI.createButton({
title : 'Send Broadcast'
});
button.addEventListener('click', function() {
var intent = Ti.Android.createBroadcastIntent({
action: 'com.appcelerator.action.ALERT',
data: 'http://www.appcelerator.com'
});
Ti.Android.currentActivity.sendBroadcast(intent);
});
win.add(button);
win.open();
var broadcastReceiver = Ti.Android.createBroadcastReceiver({
onReceived: function(e) {
Ti.API.info(JSON.stringify(e.intent));
}
});
Ti.Android.registerBroadcastReceiver(broadcastReceiver, ['com.appcelerator.action.ALERT']);
The 'data' in this case (most likely) is being used incorrectly. The 'data' of an intent is the data to operate on. Check here for clarification: http://developer.android.com/reference/android/content/Intent.html Related readings just for anyone's reference (mainly for me):- http://docs.appcelerator.com/platform/latest/#!/guide/Android_Intents-section-43287298_AndroidIntents-AddExtraData http://docs.appcelerator.com/platform/latest/#!/guide/Android_Broadcast_Intents_and_Receivers
I would assume you want to send some form of information or text over. Here's an example how:
[~bhatfield] If the answer is acceptable, can this ticket be closed?
Closing ticket as invalid.