I have a code in android that performs an alarm, but I have to register and then check some values, for example day of the week, and have an option called mode, which comes down to "Vibrate" and "Play".
Pieces of code:
public class Alarme_Receiver extends BroadcastReceiver {
AlarmManager alarmManager;
private PendingIntent pendingIntent;
private AudioManager myAudioManager;
@Override
public void onReceive(Context context, Intent intent) {
// For our recurring task, we'll just display a message
myAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (Modo.valor == "Vibrar") {
myAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
Toast.makeText(context, "Setando modo Vibracal", Toast.LENGTH_SHORT).show();
} else {
if (Modo.valor == "Tocar") {
myAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Toast.makeText(context, "Setando modo normal", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Erro " + Modo.valor, Toast.LENGTH_SHORT).show();
}
}
if (alarmManager != null) {
alarmManager.cancel(pendingIntent);
}
}
}
final Calendar c = Calendar.getInstance();
int hour = tmp.getHour();
int minute = tmp.getMinute();
c.set(Calendar.HOUR_OF_DAY, hour);
c.set(Calendar.MINUTE, minute);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
String ho = String.valueOf(hour);
String mi = String.valueOf(minute);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(cadastro.this, Alarme_Receiver.class);
final int _id = (int) System.currentTimeMillis();
PendingIntent appIntent = PendingIntent.getBroadcast(cadastro.this, _id, intent, PendingIntent.FLAG_ONE_SHOT);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), appIntent);
Toast.makeText(getApplicationContext(), "Alarme setado para as " + ho + "h e " + mi + " minutos" + Modo.valor, Toast.LENGTH_LONG).show();
kill_activity();
}