Monday, 31 October 2016

BroadCast Receiver

 BroadCast Receiver is also called as "Communicate Collector". It is a component.

A communicate collector is an Android segment which permits to enlist and listen for gadget introduction changes like sms message received , telephone call received/pick/cut ,battery status changed, the Wi-Fi went ahead.

Android working framework and even different applications time to time communicate messages about things that are occurring like sms messsage recieved , telephone call recieved/pick/cut ,battery status changed, the Wi-Fi went ahead.

With the assistance of communicate recipient you will find Android working framework particular occasions and after that you can code your application for that occasion.

Example :-
                      Your Battery Getting low.
                      Your Phone has suddenly Turn off.
                      Your Battery 10% to 20% remaining.
                      Image Capture also broadcast receiver.

Syntax :-
                In android mainfest.xml,

                   <receiver android:name="MainActivity">  
                    <action android:name="com.kiranapp.BroadCast Receiver">


               public class MainActivity extends Broadcast Receiver
                 public void onReceive(Context context, Intent intent)
  Example Code for BroadCast Receiver  shownbelow.

activity_main.xml :-

<?xml version="1.0" encoding="utf-8"?> 
 android:text="Battert status is : " 
 android:background="#f3ecec" />
</LinearLayout> :-

package com.kiranapp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
 TextView t1;

 protected void onCreate(Bundle savedInstanceState) {
 registerReceiver(new MyBro(),new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
class MyBro extends BroadcastReceiver{
 public void onReceive(Context context, Intent intent) {
 int bstatus=intent.getIntExtra("level",0);
 t1.setText("Battery Status is : "+bstatus);

Output :-

BroadCast Receiver
BroadCast Receiver Figure


  1. I have completely read your post and the content is crisp and clear. Thank you for posting such an informative article, I have decided to follow your blog so that I can myself updated.Android Training in Bangalore