Skip to main content

Posts

Showing posts with the label Broadcast

Android Application Fundamentals or Components

See more basics on Android along with interview questions Android is written in java programming language.Android application are composed of some of the main components such as: Activities Services Content providers Broadcast receivers Intents, Resources(such as strings and graphics), Notification signalings(light,sound,dialog), are also part of the components. All these components play different role in the overall application and each one can be activated individually. Activities :           An activity represents a single screen with a user interface.Suppose if there is a listview and if clicking on each row it traverse to another page ,then the screen showing listview is an activity and the next page is another activity,where each one is independent of the others. An activity is implemented as a subclass of Activity ,that why we use see activity life cycle here : public class MainActivity extends Activity { } ...

BroadcastReceiver for Screen On/Off in ANDROID

If wanted to call a broadcast for screen on/off you can get the code sniffet from here. Here I have used dynamic calling of Broadcast and the java source code is given below. get more details about broadcast from :    Broadcast Receiver Introduction in Android    BroadcastReceiver to get Battery Level in java file: public class MainActivity extends Activity { //Create broadcast object BroadcastReceiver mybroadcast = new BroadcastReceiver() { //When Event is published, onReceive method is called @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Log.i("[BroadcastReceiver]", "MyReceiver"); if(intent.getAction().equals(Intent.ACTION_SCREEN_ON)){ Log.i("[BroadcastReceiver]", "Screen ON"); } else if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){ Log.i("[BroadcastReceiver]", "Screen ...

BroadcastReceiver to get Battery Level - simple Example using dynamic calling of BroadCast in ANDROID

See Introduction for Broadcast Receiver here:  When you need to call a broadcast (suppose here battery value) you need to register the broadcast and when the event is published it will call onReceive method which have context and particular intent as parameter. public class Broadcast extends Activity { //Create broadcast object BroadcastReceiver mybroadcast = new BroadcastReceiver() { //When Event is published, onReceive method is called @Override public void onReceive(Context context, Intent intent) { //Get battery percentage int batterylevel = intent.getIntExtra("level", 0); //get progressbar ProgressBar myprogressbar = (ProgressBar) findViewById(R.id.progressbar); myprogressbar.setProgress(batterylevel); TextView tv = (TextView) findViewById(R.id.textfield); //Set TextView with text tv.setText("Battery Level: " + Integer.toString(batterylevel) + "%"); } }; @Override p...