Friday, 23 March 2018

Broadcast Receiver

Hi all,
See the code for Broadcast receiver


<application
   android:icon="@drawable/ic_launcher"
   android:label="@string/app_name"
   android:theme="@style/AppTheme" >
   <receiver android:name="MyReceiver1">
  
      <intent-filter>
         <action android:name="android.intent.action.DATE_CHANGED">
         </action>
      </intent-filter>
  
   </receiver>
</application>

--------------------------------------------------------------------------------------------------------
package com.example.tutorialspoint7.myapplication;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

/**
 * Created by TutorialsPoint7 on 8/23/2016.
 */
public class MyReceiver1 extends BroadcastReceiver{
   @Override
   public void onReceive(Context context, Intent intent) {
      Toast.makeText(context, "Date Changed.", Toast.LENGTH_LONG).show();
   }
}
------------------------------------------------------------------------------------------------------------------

Find a few such broadcasts

1             

android.intent.action.BATTERY_LOW

Indicates low battery condition on the device.
2             

android.intent.action.BATTERY_CHANGED

Sticky broadcast containing the charging state, level, and other information about the battery.

3             

android.intent.action.BATTERY_OKAY

Indicates the battery is now okay after being low.
4             

android.intent.action.BOOT_COMPLETED

This is broadcast once, after the system has finished booting.
5             

android.intent.action.BUG_REPORT

Show activity for reporting a bug.

6            

android.intent.action.CALL_BUTTON

The user pressed the "call" button to go to the dialer or other appropriate UI for placing a call.
7            

android.intent.action.CALL

Perform a call to someone specified by the data.
8             

android.intent.action.DATE_CHANGED

The date has changed.
9             

android.intent.action.REBOOT

Have the device reboot.


No comments:

Post a Comment