2017-10-10 15 views
-1

複数の日のアラームを設定してアラームアプリケーションを作成しています。私はすでに1日アラームを設定していますが、選択した日に同じアラームを設定する方法はわかりません。複数の日を選択するには、checkboxesを使用します。ここで選択された日に毎週リピートアラームを設定します

私は、ユーザーが選択した日を得る:例として

//set alarm repeat days method 
public void showDialogAlarmdays() { 

    setRepeatTxt.setOnClickListener(
      new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        selections=""; 
        ad.show(); 
       } 
      } 
    ); 

    final String[] items=getResources().getStringArray(R.array.my_date_choose); 

    android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(this); 
    // Set the dialog title 
    builder.setTitle("Choose your days"); 
    // Specify the list array, the items to be selected by default (null for none), 
    // and the listener through which to receive callbacks when items are selected 
    builder.setMultiChoiceItems(R.array.my_date_choose, null, 
      new DialogInterface.OnMultiChoiceClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which, 
            boolean isChecked) { 
        if (isChecked) { 
         // If the user checked the item, add it to the selected items 
         mSelectedItems.add(items[which]); 
        } else if (mSelectedItems.contains(items[which])) { 
         // Else, if the item is already in the array, remove it 
         mSelectedItems.remove(items[which]); 
        } 
       } 
      }); 
    // Set the action buttons 
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int id) { 
      selections=""; 
      for (String ms:mSelectedItems) { 
       if(selections==""){ 
        selections=ms; 
       }else{ 
        selections=selections+","+ms; 
       } 

      } 
      // Toast.makeText(addTimeSlot.this,selections, Toast.LENGTH_LONG).show(); 
      if(selections.equals("")){ 
       showRepeatTxt.setText("Choose your days"); 
      }else{ 
       showRepeatTxt.setText(selections); 
      } 
       //Toast.makeText(setAlarm.this,selections, Toast.LENGTH_LONG).show(); 
     } 
    }); 
    builder .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int id) { 

     } 
    }); 

    ad = builder.create(); 
} 

、ユーザーが月曜日、火曜日と金曜日を選択した場合、アラームはその選択日間繰り返す必要があります。設定したアラームのための

ここ方法:

alarm_start.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      //Toast.makeText(setAlarm.this,hour+" : "+min, Toast.LENGTH_SHORT).show(); 

      //celender set time 
      calendar.set(Calendar.HOUR_OF_DAY,Cal_hour); 
      calendar.set(Calendar.MINUTE,Cal_minute); 

      //put extra string into Alarm_intent 
      //tells the clock that you pressed the 'OK' button 
      Alarm_intent.putExtra("extra","on"); 

      //put extra int into Alarm_intent 
      //tells the clock that you want to certain value from spinner 
      Alarm_intent.putExtra("ringtoneChoice",choose_ringtone); 

      Log.e("Ringtone id : ", String.valueOf(choose_ringtone)); 

      //create a pending intent that delay the intent until the specified calendar time 
      pending_intent = PendingIntent.getBroadcast(setAlarm.this.getApplicationContext(),0, 
        Alarm_intent,pending_intent.FLAG_UPDATE_CURRENT); 

      //set the alarm manager 
      alarm_Manager.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), 
        pending_intent); 


      Toast.makeText(setAlarm.this,"Alarm is set...!", Toast.LENGTH_SHORT).show(); 
      finish(); 
     } 
    }); 

ここでは、Calendar.set(Calendar.HOUR_OF_DAY、Cal_hour)とは、Calendar.set(Calendar.MINUTE、Cal_minute)の値は、時間ピッカーから取得します。

答えて

0
Intent myIntent = new Intent(AndroidAlarmService.this, MyAlarmService.class); 
    pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0); 

    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE); 

      Calendar calendar = Calendar.getInstance(); 
      calendar.setTimeInMillis(System.currentTimeMillis()); 
      calendar.add(Calendar.SECOND, 10); 
      //alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent); 
      alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 5*1000, pendingIntent); 
関連する問題