2015-02-05

Android BroadcastReceiver

Untuk bagian broadcast:

Intent intent = new Intent();
intent.setAction(receiver);
intent.putExtra("pagi","Selamat pagi.");
sendBroadcast(intent);

Untuk bagian receiver:

// Buat receiver.
BroadcastReceiver bReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String str = intent.getStringExtra("pagi");
        Log.d(TAG,str);
    }
};
// Buat filter.
IntentFilter filter = new IntentFilter();
filter.addAction(receiver);
// Daftarkan receiver dan filter.
registerReceiver(bReceiver,filter);

 

Source code:
download

You may also like...

2 Responses

  1. Hariyanto says:

    how can i implement this code ? thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *