Broadcast receiver


I’m new to android, I’m trying to do an application using Broadcast Receiver which send the message to notification bar when wallpaper is changed on device. It’s successfully installed on device but not working as expected. Here is the code

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

import android.util.Log;
import android.widget.Toast;

public class WallPaperNotificationReceiver extends BroadcastReceiver {

                public void onReceive(Context context, Intent intent) {
                                this.sendNotification(context, "You have changed Wallpaper");
    private void sendNotification(Context ctx, String message)
                //Get the notification manager
                String ns = Context.NOTIFICATION_SERVICE;
                NotificationManager nm =

                //Create Notification Object
                                int icon = R.drawable.ic_launcher;
                                CharSequence tickerText = "Hello";
                                long when = System.currentTimeMillis();

                                Notification notification =
                                                new Notification(icon, tickerText, when);

                                //Set ContentView using setLatestEvenInfo
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    PendingIntent pi = PendingIntent.getActivity(ctx, 0, intent, 0);
                    notification.setLatestEventInfo(ctx, "Intimation", message, pi);

                    //Send notification
                                nm.notify(1, notification);
                                Toast.makeText(ctx,"Hello Nawin",Toast.LENGTH_LONG).show();



<xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />

        android:label="@string/app_name" >

    <receiver android:name=".WallPaperNotificationReceiver">
            <action android:name="android.intent.action.WALLPAPER_CHANGED" />

Is this right way to use Broadcast receiver? if so Help me where I did a mistake?

Thanks in Advance.

P.S: I’m not using either Activity or Service. According to the process life cycle we can have a foreground process by hosting a broadcast receiver

Since Android version 3.1 BroadcastReceivers that are registered only in the manifest and in an app which has no Activity, will not work. Each app must have an activity which must be run at least once to enable the receiver to work. This is to prevent malware. You just need a dummy activity which does nothing then quits to run once and make your receiver work.