Last active
November 13, 2018 22:43
-
-
Save RedRussianBear/77f05ff5c78d4d88c06007dd77d029e0 to your computer and use it in GitHub Desktop.
ClarifaiAlarm Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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