title: how to Scheduled Notifications in Android on a specified time with TimePicker on android studio
body: <p>i want to send reminder on selected time using time picker from my application automatically or to activate particulate class on user selected time.</p>
  
  <p>here is my code</p>
  
  <pre><code>public class Time_Picker extends Activity {
      TimePicker myTimePicker;
      Button buttonstartSetDialog,buttonCancelAlarm;;
      TextView textAlarmPrompt;
      private String format = "";
  
      TimePickerDialog timePickerDialog;
  
      final static int RQS_1 = 1;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.timepicker);
  
          myTimePicker = (TimePicker) findViewById(R.id.timePicker1);
          textAlarmPrompt = (TextView)findViewById(R.id.alarmprompt);
  
          Calendar calendar = Calendar.getInstance();
          calendar = Calendar.getInstance();
          myTimePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
          myTimePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));
  
          buttonstartSetDialog = (Button)findViewById(R.id.startSetDialog);
          buttonstartSetDialog.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  textAlarmPrompt.setText("");
                  openTimePickerDialog(false);
  
              }
          });
          buttonCancelAlarm = (Button)findViewById(R.id.cancel);
          buttonCancelAlarm.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
                  cancelAlarm();
              }
          });
  
      }
      private void openTimePickerDialog(boolean is24r){
          Calendar calendar = Calendar.getInstance();
          int hour = calendar.get(Calendar.HOUR_OF_DAY);
          int min = calendar.get(Calendar.MINUTE);
          Calendar current = Calendar.getInstance();
  
          Calendar cal = Calendar.getInstance();
          cal.set(myTimePicker.getCurrentHour(),
                  myTimePicker.getCurrentMinute(), 00);
  
              setAlarm(cal);
      }
  
  private void setAlarm(Calendar targetCal){
          textAlarmPrompt.setText(
                  "\n\n***\n"
                          + "Alarm is set@ " + targetCal.getTime() + "\n"
                          + "***\n");
  
          Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
          PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0);
          AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
          alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);
      }
  </code></pre>
  
  <p>here is my AlaramReciver.java</p>
  
  <pre><code> @Override
      public void onReceive(Context arg0, Intent arg1) {
          Toast.makeText(arg0, "Alarm received!", Toast.LENGTH_LONG).show();
  
          Vibrator vibrator = (Vibrator) arg0.getSystemService(Context.VIBRATOR_SERVICE);
          vibrator.vibrate(2000);
  
          Intent i = new Intent(arg0, DailyReport_CSV_file.class);
          i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          arg0.startActivity(i);
      }
  </code></pre>
  
  <p>timepicker.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:background="#ffffff"&gt;
      &lt;LinearLayout
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:padding="8dp"
          android:background="#0a608e"
          android:gravity="center_horizontal"&gt;
  
          &lt;ImageButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/gobackb"
              android:background="?android:selectableItemBackground"
              tools:targetApi="honeycomb"
              android:src="@drawable/whitearrows"
              android:padding="10dp" /&gt;
  
          &lt;TextView
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:textAppearance="?android:attr/textAppearanceLarge"
              android:text="Daily report dispatch time"
              android:textColor="#ffffff"
              android:textSize="20sp"
              android:gravity="center_horizontal"
              android:paddingTop="10dp"
              android:paddingRight="15dp"
              /&gt;
  
      &lt;/LinearLayout&gt;
      &lt;TextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceMediumInverse"
          android:text="Set daily report dispatch time "
          android:id="@+id/textView33"
          android:textColor="#ffffff"
          android:background="#074363"
          android:padding="10dp" /&gt;
  
      &lt;LinearLayout
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;
  
          &lt;TimePicker
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/timePicker1"
              android:layout_gravity="center_horizontal" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:gravity="center_horizontal"
          android:padding="10dp"&gt;
  
          &lt;Button
              android:id="@+id/startSetDialog"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Set Target Time"/&gt;
  
          &lt;Button
              android:id="@+id/cancel"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Cancel Alarm"/&gt;
      &lt;/LinearLayout&gt;
      &lt;TextView
          android:id="@+id/alarmprompt"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Now i want to activate a class on user selected time on time picker  </p>