Broadcast Receiver Introduction in Android

Posted by Unknown Rabu, 03 April 2013 0 komentar
A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. There are two ways to use broad cast receiver in android --
  • One is using dynamically in activity
  • Second to register through manifest
Using dynamically in activity
Register broadcast receiver Via dynamically ( Run time )
 
// Create reciever object
private BroadcastReceiver the_receiver = new PhoneCall();
// Set When broadcast event will fire.
private IntentFilter filter = new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED);
// Register new broadcast receiver
this.registerReceiver(the_receiver, filter);
// Reciever class which extends BroadcastReceiver
public class PhoneCall extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
// Phone call state change then this method will automaticaly called
}
}
Register through manifest
Register broadcast receiver Via the AndroidManifest.xml file.
 





When android.intent.action.PHONE_STATE Event will fire ( call recieved/pick/end ), then onReceive method in PhoneCall.java file will automaticaly call.
Now Create PhoneCall.java file
 
// Reciever class which extends BroadcastReceiver
public class PhoneCall extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
// Phone call state change then this method will automaticaly called
}}
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Broadcast Receiver Introduction in Android
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke http://androidpopuler.blogspot.com/2013/04/broadcast-receiver-introduction-in.html. Terima kasih sudah singgah membaca artikel ini.

0 komentar:

Posting Komentar

Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android populer.