title: Notification from broadcastreceiver
body: <p>I'm building an alarm clock which will show notification after desired time . For this I have used alarmmanager and broadcastreceiver to display notification.
  I have used notification builder to build the notification .My problem is that broadcastreceiver is not displaying notification at given time .</p>
  
  <p>MainActivty.java   </p>
  
  <pre><code>import android.app.Activity;
  import android.app.AlarmManager;
  import android.app.PendingIntent;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  public class MainActivity extends Activity {
  
      int i=0;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          Button button = (Button)findViewById(R.id.button1);
          final EditText et = (EditText)findViewById(R.id.et);
          button.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  String s = et.getText().toString();
                  int time = Integer.parseInt(s);
                  setAlarm(time);
              }
          });
      }
  
      public void setAlarm(int time){
          i++;
          Intent intent = new Intent(this, MyBroadcastReceiver.class);
          PendingIntent pendingIntent = PendingIntent.getBroadcast(
         this.getApplicationContext(), i, intent, 0);
          AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
          alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
         + (time * 1000), pendingIntent);
          Toast.makeText(this, "Alarm set in " + time + " seconds",
         Toast.LENGTH_LONG).show();
      }
  
  
  }
  </code></pre>
  
  <p>MyBroadcastReceiver.java</p>
  
  <pre><code>import android.app.NotificationManager;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.support.v4.app.NotificationCompat;
  
  public class MyBroadcastReceiver extends BroadcastReceiver {
       @Override
       public void onReceive(Context context, Intent intent) {
          /**Toast.makeText(context, "Time is up!!!!.",
         Toast.LENGTH_LONG).show();
          // Vibrate the mobile phone
          Vibrator vibrator = (Vibrator) context
        .getSystemService(Context.VIBRATOR_SERVICE);
          vibrator.vibrate(2000);
          **/
          NotificationCompat.Builder builder = new NotificationCompat.Builder(
                  context)
                  // Set Icon
                  //.setSmallIcon(R.drawable.logosmall)
                  // Set Ticker Message
                  .setTicker("ticker")
                  // Set Title
                  .setContentTitle("new Notification")
                  // Set Text
                  .setContentText("new message")
                  // Add an Action Button below Notification
                  //.addAction(R.drawable.ic_launcher, "Action Button", pIntent)
                  // Set PendingIntent into Notification
                  //.setContentIntent(pIntent)
                  // Dismiss Notification
                  .setAutoCancel(true);
  
  
  
          NotificationManager notificationmanager = (NotificationManager) context
                  .getSystemService(Context.NOTIFICATION_SERVICE);
          // Build Notification with Notification Manager
          notificationmanager.notify(0, builder.build());
  
       }
  }
  </code></pre>
  
  <p>xml layout</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.example.alarm.MainActivity" &gt;
  
  
      &lt;EditText 
          android:id="@+id/et"
          android:layout_width="100dp"
          android:layout_height="wrap_content"/&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/timePicker1"
          android:layout_below="@+id/timePicker1"
          android:layout_marginLeft="89dp"
          android:layout_marginTop="26dp"
          android:text="Button" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Android manifest</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.alarm"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-permission android:name="android.permission.VIBRATE" /&gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="21" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;receiver android:name="MyBroadcastReceiver" &gt;
          &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I hope question is clear :) </p>