Skip to content

Instantly share code, notes, and snippets.

@RedRussianBear
Last active November 13, 2018 22:43
Show Gist options
  • Save RedRussianBear/77f05ff5c78d4d88c06007dd77d029e0 to your computer and use it in GitHub Desktop.
Save RedRussianBear/77f05ff5c78d4d88c06007dd77d029e0 to your computer and use it in GitHub Desktop.
ClarifaiAlarm Gist
public static final String EXTRA_MESSAGE = "com.example.clarifaialarm.MESSAGE";
public void setAlarm(View view) throws ParseException {
// Retrieve text editors
EditText date = findViewById(R.id.date);
EditText hour = findViewById(R.id.hour);
EditText minute = findViewById(R.id.minute);
EditText object = findViewById(R.id.object);
// Compile date-time for alarm to go off
String dateString = date.getText().toString() + " " + hour.getText().toString() + ":" + minute.getText().toString();
// Parse date-time
Date dateTime = (new SimpleDateFormat("yy-MM-dd HH:mm")).parse(dateString);
// Create intent to set off the alarm
Intent alarmIntent = new Intent(this, AlarmActivity.class);
alarmIntent.putExtra(EXTRA_MESSAGE, object.getText().toString());
// Retrieve AlarmManager
AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
// Set alarm for intended date-time to open AlarmActivity
alarmManager.set(AlarmManager.RTC_WAKEUP, dateTime.getTime(),
PendingIntent.getActivity(this, 1, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT));
// Close the activity
finish();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment