samedi 23 juillet 2016

When i select the Checkbox my alarm is running.It does not work for selected time

Here i select time using Edittext and select checkbox to perform the alarm.My selected time is not working, when i select the checkbox it start ringing

ca = Calendar.getInstance();
            mHour = ca.get(Calendar.HOUR_OF_DAY);
            //timeET.getCurrentHour();
            mMinute = ca.get(Calendar.MINUTE);
            TimePickerDialog timePickerDialog = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    timeET.setText(hourOfDay +" : "+minute);
                }
            },mHour,mMinute,false);
            timePickerDialog.show();
            fixTime = timeET.getText().toString();
    }


}

View.OnClickListener checkboxClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        boolean checked = ((CheckBox) v).isChecked();

        if (checked){
            switch (v.getId()){
                case R.id.alarm:
                    Intent myIntent = new Intent(CountryEdit.this,AlarmReceiver.class);
                    //An pendingIntent specifies an action to take in the future
                    pendingIntent = PendingIntent.getBroadcast(CountryEdit.this,0,myIntent,0);
                    //set Alarm Time
                    alarmManager.set(AlarmManager.RTC,ca.getTimeInMillis(),pendingIntent);
                    break;
                case R.id.remainder:
                    break;

            }
        }else{
            alarmManager.cancel(pendingIntent);
        }

This is my AlarmReceiver class where i tell the system to ring for selecting time.

 @Override
public void onReceive(Context context, Intent intent) {
    //This will update the UT with message
    try{
        CountryEdit inst = CountryEdit.instance();

        //This will sound my Alarm once if i wish to sound my alarm in loop continuously then use MediaPlayer
        Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);

        if (alarmUri == null){
            alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        }

        Ringtone ringtone = RingtoneManager.getRingtone(context,alarmUri);
        ringtone.play();

    }catch (Exception ex){

    }

}

I do not know where is the problem.Is there any one please help me.I am the beginner.




Aucun commentaire:

Enregistrer un commentaire