Click here to Skip to main content
15,915,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..new to coding .

I need to get the hrs and min value form the user using numberpickers ,then add the value with current time using Calendar method, then set the alarm using AlarmClock method


Java
public class MainActivity extends AppCompatActivity {

    private NumberPicker hrs;
    private NumberPicker mins;
    private Button set;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerOnButton();

            }



    public void addListenerOnButton(){

        hrs = (NumberPicker) findViewById(R.id.numberPicker);
        mins = (NumberPicker)findViewById(R.id.numberPicker2);
        set = (Button)findViewById(R.id.button);

        hrs.setMinValue(0);
        hrs.setMaxValue(8);
        hrs.setWrapSelectorWheel(false);
        mins.setMinValue(0);
        mins.setMaxValue(60);
        mins.setWrapSelectorWheel(false);


        set.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                final Calendar now = Calendar.getInstance();
                Calendar c =(Calendar)now.clone();
                c.add(Calendar.HOUR_OF_DAY,hrs.getValue());
                c.add(Calendar.MINUTE,mins.getValue());
                Calendar time = c;

                Intent s = new Intent (AlarmClock.ACTION_SET_ALARM);
                s.putExtra(AlarmClock.EXTRA_HOUR, time.getTime());
                s.putExtra(AlarmClock.EXTRA_MINUTES, time.getTime());
                s.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
                startActivity(s);

            }
        });
    }



After running the program, I can able to select the value , but after clicking the SET button it opens the Clock application and shows the timepicker dialogue .

My aim is to , after clicking the SET button it has to set the added time as alarm
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900