[TIMOB-6142] Android: Expose createBroadcastIntent in ActivityProxy
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-09-11T06:07:54.000+0000 |
Affected Version/s | Release 1.8.0.1 |
Fix Version/s | 2013 Sprint 19, 2013 Sprint 19 API, Release 3.2.0 |
Components | Android |
Labels | exalture, module_android, qe-testadded, tbs-1.9.0 |
Reporter | Marshall Culpepper |
Assignee | Sunila |
Created | 2011-11-10T10:46:01.000+0000 |
Updated | 2014-04-21T11:26:36.000+0000 |
Description
createBroadcastIntent is not callable from Ti.Android, we need to make sure it's exposed and working as intended. We have a community pull request here:
https://github.com/appcelerator/titanium_mobile/pull/655
Test case for sendBroadcast
Run the following app, press the button therein and then check the log for "Broadcast received".
var win = Ti.UI.createWindow();
var br = Ti.Android.createBroadcastReceiver({
onReceived: function() {
Ti.API.info('Broadcast received.');
}
});
Ti.Android.registerBroadcastReceiver(br,["com.exalture.test.broadcastreceiver"]);
var sendBroadcastBtn = Ti.UI.createButton({top:100,width:300,title:"SendBroadcast"});
sendBroadcastBtn.addEventListener('click', function()
{
var intent = Ti.Android.createBroadcastIntent({
action: "com.exalture.test.broadcastreceiver"
});
Ti.Android.currentActivity.sendBroadcast(intent);
});
win.add(sendBroadcastBtn);
win.open();
Test case for sendBroadcastWithPermission.
First, you need to both define the permission and "use" it in the manifest section of the "android" section of your tiapp.xml. So make the tiapp.xml's "android" section look like this:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<permission
android:name="com.exalture.test.withPermission" />
<uses-permission android:name="com.exalture.test.withPermission"/>
</manifest>
</android>
The run the following app, press the button therein and check the log for "Broadcast received with permission":
var win = Ti.UI.createWindow();
var brWithPermission = Ti.Android.createBroadcastReceiver({
onReceived: function() {
Ti.API.info('Broadcast received with permission.');
}
});
Ti.Android.registerBroadcastReceiver(brWithPermission, ["com.exalture.test.broadcastreceiver"]);
var sendBroadcastBtn = Ti.UI.createButton({top:100,width:300,title:"SendBroadcast"});
sendBroadcastBtn.addEventListener('click', function()
{
var intentWithPermission = Ti.Android.createBroadcastIntent({
action: "com.exalture.test.broadcastreceiver"
});
Ti.Android.currentActivity.sendBroadcastWithPermission(intentWithPermission, "com.exalture.test.withPermission");
});
win.add(sendBroadcastBtn);
win.open();
Will we need to expose Activity.sendBroadcast to make this useable?
Yeah, maybe others as well
Any chance of this being implemented?
Added support for BroadcastIntent https://github.com/appcelerator/titanium_mobile/pull/4412
Updated the description with test case
Verified the fix with: Appc-Studio: 3.2.0.201310181700 Sdk:3.2.0.v20131022171645 alloy:1.2.2 npm:1.3.2 titanium:3.2.0 titanium-code-processor:1.0.3 Device:Google Nexus 7(v4.3) OS: Mac OSX 10.8 Getting logs as per test code for broadcast with and without permission. Above test code was used for testing.