0
I have a code on android that runs an alarm, only I have to register and then check some values, for example day of the week, and has an option called mode, which boils down in "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();
}
What would be your question? do you already save something in your application? Would you like to know how to save? What would you like to save exclusively?
– Thiago Luiz Domacoski
so it’s already saving the right alarm time, only I want to save the mode and the day of the week that the user type, only every time the user clicks the alarm button will have to accept new values.
– Ranieri
How are you saving? Sharedprefrences? or even Sqlite? could edit your question and put the code you use to save?
– Thiago Luiz Domacoski
I am using neither an alarm and scheduled by Alarm Manager I want to know how to save other information that and the question
– Ranieri