title: How to get notifications on particular date and time?
body: <p>Hi i am searching how to get notifications when i select date and time where date and time are saving in provider when event occurs on that date notification want to come.</p>
  
  <pre><code>package com.example.addeventsofcal;
  
  import java.sql.Date;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Calendar;
  import java.util.Locale;
  
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.app.AlarmManager;
  import android.app.DatePickerDialog;
  import android.app.DatePickerDialog.OnDateSetListener;
  import android.app.Dialog;
  import android.app.PendingIntent;
  import android.app.TimePickerDialog;
  import android.app.TimePickerDialog.OnTimeSetListener;
  import android.content.ContentValues;
  import android.content.Context;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.DatePicker;
  import android.widget.EditText;
  import android.widget.ImageView;
  import android.widget.TextView;
  import android.widget.TimePicker;
  import android.widget.Toast;
  
  
  import com.examples.android.calendar.CalendarView;
  import com.examples.android.calendar.R;
  
  
  public class Addevent extends Activity implements OnClickListener {
  
      private EditText edtDate;
      private EditText edtTime;
  
      final Calendar c = Calendar.getInstance();
  
  
      final static int RQS_1 = 1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.contentprovider);
  
          initializeView();
      }
  
      private void initializeView() {
          edtDate = (EditText) findViewById(R.id.txtDate);
          edtTime = (EditText) findViewById(R.id.txtTime);
          Intent currentIntent = getIntent();
          Bundle extras = currentIntent.getExtras();
  
          setCurrentDateOnView();
      }
  
      DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
          @Override
          public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
              final Calendar c = Calendar.getInstance();
              c.set(Calendar.YEAR, year);
              c.set(Calendar.MONTH, monthOfYear);
              c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
              // setCurrentDateOnView();
          }
      };
  
      protected DatePickerDialog Date;
  
      TimePickerDialog.OnTimeSetListener time = new TimePickerDialog.OnTimeSetListener() {
          @Override
          public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
  
              final Calendar c = Calendar.getInstance();
              c.set(Calendar.HOUR_OF_DAY, hourOfDay);
              c.set(Calendar.MINUTE, minute);
              Date = new DatePickerDialog(Addevent.this, date, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
              setAlarm(Date, true);
          }
  
          private void setAlarm(Date targetCal, boolean isEditMode) {
              Intent myIntent = new Intent(Addevent.this, MyReceiver.class);
              myIntent.putExtra("MODE", isEditMode);
              myIntent.putExtra("time", targetCal.getTime());
  
              pendingIntent = PendingIntent.getBroadcast(Addevent.this, 0, myIntent, 0);
  
              AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
              alarmManager.set(AlarmManager.RTC, targetCal.getTime(), pendingIntent);
          }
      };
  
      private PendingIntent pendingIntent;
  
      public void dateOnClick(View view) {
          new DatePickerDialog(Addevent.this, date,
                  c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH)).show();
  
      }
  
      public void timeOnClick(View view) {
          new TimePickerDialog(Addevent.this, time,
                  c.get(Calendar.HOUR), c.get(Calendar.MINUTE), false).show();
      }
  
      public void setCurrentDateOnView() {
          String dateFormat = "yyyy-MM-dd";
          SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.US);
          edtDate.setText(sdf.format(c.getTime()));
  
          String timeFormat = "hh:mm a";
          SimpleDateFormat stf = new SimpleDateFormat(timeFormat, Locale.US);
          edtTime.setText(stf.format(c.getTime()));
      }
  
      public void onClickAddName(View view) {
          // Add a new student record
          ContentValues values = new ContentValues();
  
          values.put(StudentsProviders.NAME,
                  ((EditText) findViewById(R.id.txtName)).getText().toString());
  
          values.put(StudentsProviders.Description,
                  ((EditText) findViewById(R.id.txtGrade)).getText().toString());
  
  
          values.put(StudentsProviders.DATE,
                  ((EditText) findViewById(R.id.txtDate)).getText().toString());
  
  
          values.put(StudentsProviders.Time,
                  ((EditText) findViewById(R.id.txtTime)).getText().toString());  
  
          Uri uri = getContentResolver().insert(StudentsProviders.CONTENT_URI, values);
          Toast.makeText(getBaseContext(), uri.toString(), Toast.LENGTH_LONG).show();  
          Intent returnIntent = new Intent(Addevent.this, CalendarView.class);
          startActivity(returnIntent);
      }
  
      @Override
      public void onClick(View v) {
          // TODO Auto-generated method stub      
      }
  }
  </code></pre>
  
  <p>Please suggest me how to get notifications when we timepicker listener. As I add set alaram I am getting error date can't be cast when I cast the date in set alaram. Please suggest how to solve it.</p>