Note that there are some explanatory texts on larger screens.

plurals
  1. POSet android alarm clock programmatically
    text
    copied!<p>I'm trying to build a personal app that will set alarms in the DeskClock app. I can get it to set alarms for anytime in the current day, But how would I go about setting an alarm for the next day, or later in the week. Looking through the AlarmClock api in android I don't see a normal way to do this. Is this even possible?</p> <p>Btw this is my code for setting the alarm it might not be pretty, but I am learning as I go.</p> <pre><code> package com.netwokz.setit; import java.util.Calendar; import java.util.GregorianCalendar; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.provider.AlarmClock; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity implements OnClickListener { Button btnSetAlarm; EditText etHour, etMinute; int minute, hour, day; Calendar cal; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); btnSetAlarm = (Button) findViewById(R.id.btn_set_alarm); etHour = (EditText) findViewById(R.id.etHour); etMinute = (EditText) findViewById(R.id.etMinute); btnSetAlarm.setOnClickListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main_activity, menu); return true; } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_set_alarm: setAlarm(); break; } } private void setAlarm() { cal = new GregorianCalendar(); cal.setTimeInMillis(System.currentTimeMillis()); day = cal.get(Calendar.DAY_OF_WEEK); hour = cal.get(Calendar.HOUR_OF_DAY); minute = cal.get(Calendar.MINUTE); Intent i = new Intent(AlarmClock.ACTION_SET_ALARM); i.putExtra(AlarmClock.EXTRA_HOUR, hour + Integer.parseInt(etHour.getText().toString())); i.putExtra(AlarmClock.EXTRA_MINUTES, minute + Integer.parseInt(etMinute.getText().toString())); i.putExtra(AlarmClock.EXTRA_SKIP_UI, true); startActivity(i); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload