Necesito crear un botón y definirle una hora (alarma). El caso es que cuando el usuario de la app dé click en el botón, se active dicha alarma.
He intentado y buscado más, pero todos utilizan TimePicker
. El código que tengo es más o menos así:
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;
import java.util.Calendar;
/**
* Created by diego on 11/06/2017.
*/
public class alarm {
private int horas;
private int minutos;
private TimePicker timePicker;
private Button button_alarm = (Button)findViewById(R.id.button_alarm);
private AlarmManager alarmaManager;
private PendingIntent alarmaIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm);
Context context = null;
alarmaManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmActivity.class);
alarmaIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
button_alarm.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onClick(View v) {
horas = timePicker.getHour(14);
minutos = timePicker.getMinute();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, horas);
calendar.set(Calendar.MINUTE, minutos);
}
});
}
private void findViewById(int button_alarm) {
button_alarm
}
public AlarmManager getAlarmaManager() {
return alarmaManager;public void setContentView(int contentView) {
this.contentView = contentView;
}
}
public void setAlarmaManager(AlarmManager alarmaManager) {
this.alarmaManager = alarmaManager;
}
public PendingIntent getAlarmaIntent() {
return alarmaIntent;
}
public void setAlarmaIntent(PendingIntent alarmaIntent) {
this.alarmaIntent = alarmaIntent;
}
}