Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6142] Android: Expose createBroadcastIntent in ActivityProxy

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2013-09-11T06:07:54.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/s2013 Sprint 19, 2013 Sprint 19 API, Release 3.2.0
ComponentsAndroid
Labelsexalture, module_android, qe-testadded, tbs-1.9.0
ReporterMarshall Culpepper
AssigneeSunila
Created2011-11-10T10:46:01.000+0000
Updated2014-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();

Comments

  1. Josh Roesslein 2011-11-10

    Will we need to expose Activity.sendBroadcast to make this useable?
  2. Marshall Culpepper 2011-11-11

    Yeah, maybe others as well
  3. Tommy Leung 2013-01-16

    Any chance of this being implemented?
  4. Sunila 2013-06-24

    Added support for BroadcastIntent https://github.com/appcelerator/titanium_mobile/pull/4412
  5. Sunila 2013-07-30

    Updated the description with test case
  6. Priya Agarwal 2013-10-23

    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.

JSON Source