私は助けが必要です。アンドロイドコーディングは初めてです。
タスクに書かれた時間に具体的にやりたいタスクリストを作りました。
ここに私のタスク項目があります
private long id;
private int mon;
private int tues;
private int wednes;
private int thurs;
private int fri;
private int satur;
private int sun;
private int profile;
分数を保持する日(月曜日、火曜日など)があります(10:00の場合、600)。
いくつかのチュートリアルに従って、アラーム受信機を持っています
public class AlarmReciever extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
try {
Bundle bundle = intent.getExtras();
String message = bundle.getString("alarm_message");
Intent newIntent = new Intent(context, AlarmActivity.class);
newIntent.putExtra("profile", message);
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(newIntent);
} catch (Exception e) {
Toast.makeText(context, "There was an error somewhere, but we still received an alarm", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
まだ未編集です…
そして、アラームマネージャーで新しいタスクを作成するために呼び出すコードがあります
// get a Calendar object with current time
Calendar cal = Calendar.getInstance();
// add 5 minutes to the calendar object
cal.add(Calendar.MINUTE, 5);
Intent intent = new Intent(ctx, AlarmReceiver.class);
intent.putExtra("alarm_message", "O'Doyle Rules!");
// In reality, you would want to have a static variable for the request code instead of 192837
PendingIntent sender = PendingIntent.getBroadcast(this, 192837, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Get the AlarmManager service
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
カレンダーで指定する方法がわかりません。たとえば、毎週月曜日の 10:00 に新しいタスクを繰り返す必要があり、これが発生すると、新しい関数を呼び出して、操作する「プロファイル」変数を与えます。
private void setProfile(Integer profile)
{
// Doing things with profile
}