title: Broadcast Receiver
body: <p>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 </p>
  
  <p>WallPagerNotificationReceiver.java</p>
  
  <pre><code>import android.app.Notification;
  import android.app.NotificationManager;
  import android.app.PendingIntent;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.net.Uri;
  
  import android.util.Log;
  import android.widget.Toast;
  
  public class WallPaperNotificationReceiver extends BroadcastReceiver {
  
                  @Override
                  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 =
                                  (NotificationManager)ctx.getSystemService(ns);
  
                  //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);
                      intent.setData(Uri.parse("http://www.google.com"));
                      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();
      }
  
  }
  </code></pre>
  
  <p>Manifest.xlm </p>
  
  <pre><code>&lt;xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="in.ac.srmuniv"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk android:minSdkVersion="15" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
  
      &lt;receiver android:name=".WallPaperNotificationReceiver"&gt;
             &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.WALLPAPER_CHANGED" /&gt;
              &lt;/intent-filter&gt;
      &lt;/receiver&gt;
   &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Is this right way to use Broadcast receiver? if so Help me where I did a mistake? </p>
  
  <p>Thanks in Advance.</p>
  
  <p>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 <a href="http://developer.android.com/guide/components/processes-and-threads.html#Threads" rel="nofollow">http://developer.android.com/guide/components/processes-and-threads.html#Threads</a></p>