Using Broadcast Receiver in Titanium 3.0 for Android apps
Posted By : Deepankar katiyar | 20-Nov-2013
In this blog I will discuss about usingBroadcastRecevier in Titanium Binding of an Android Broadcast Receiver. Basically Broadcast Receiver respond to broadcast messages from other application or from the System it self. These messages are some time called events or intents. A broadcast receiver is a component, which allows you to register for system application events. All registered receivers for an event will be notified by the runtime once this event happens
Here You will create createBroadcastReceiver in titanium.
- Create a new Project in titanium.
- Now, replace your “apps.js “ code.
- First create a window.
var win = Ti.UI.createWindow({ backgroundColor : 'white', });
- Broadcast receivers can be created with an on Received callback or a url property
- First create a broadcast receiver.
var broadCast = Ti.Android.createBroadcastReceiver({ onReceived : function() { } });
- then, Register broadcast receiver.
Ti.Android.registerBroadcastReceiver(broadCast, [Ti.Android.ACTION_AIRPLANE_MODE_CHANGED]);
Here First parameter is name of the your broadcast and second one is which action you performed this broadcast.
- Here is "apps.js" file where you are create a Broadcast.
ar win = Ti.UI.createWindow({ backgroundColor : "white", }); var broadCast = Ti.Android.createBroadcastReceiver({ onReceived : function() { alert("AirPlane mode is Change"); } }); Ti.Android.registerBroadcastReceiver(broadCast, [Ti.Android.ACTION_AIRPLANE_MODE_CHANGED]); win.open();
This screen shows the Broadcast Receiver in titanium.
When you change the mode than event is Fire.
- Here is "apps.js" file where you are create a BroadcastRecevier .
var win = Ti.UI.createWindow({ backgroundColor : "white", }); var broadCast = Ti.Android.createBroadcastReceiver({ onReceived : function() { alert("AirPlane mode is Change"); } }); Ti.Android.registerBroadcastReceiver(broadCast, [Ti.Android.ACTION_AIRPLANE_MODE_CHANGED]); win.open();
Thanks, Deepankar Katiyar
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Deepankar katiyar
Deepanker is an iPhone and Android application developer with experience in Titanium and Phonegap frameworks.