0

特定の繰り返しアラームをスケジュールする必要があります。これは、曜日を問わず、数日間発生する可能性があります。月曜日、平日、週末のみのいずれでもかまいません。もちろん、これは DB に格納する必要があります。

私の質問は、どうすればこれを DB に保存できますか? 7 つの位置の int 配列を使用することを考えました。どの位置が true (または 1) であるかに応じて、そのようにアラームがあると想定します。

他のアイデアはありますか?提案してください?

よろしくお願いします。

4

4 に答える 4

0

follow up on Diego answer You typically use the AlarmManager for this. Create an intent that will wake up the below AlarmReceiver.class that is a BroadcastReceiver. AlarmManager is firing of this intent at your dateForAlarm. The dateForAlarm can be a String in the DB like "2009-04-14 15:16:45"

When device is restarted you need to recreate all alarms and use another or same BroadcastReceiver to get all dateForAlarm from DB and create the alarms.

put this in your manifest to capture a restart signal to your BroadcastReceiver

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Code:

Calendar dateForAlarm = "yyyy-MM-dd HH:mm:ss" // example date.."2009-04-14 15:16:45"
Intent intent = new Intent(context, MyBroadcastReceiver.class);
intent.putExtra(WAKE_UP_AND_ALARM_NOW, "value you want to send to MyBroadcastReceiver like "god morning"");
PendingIntent sender = PendingIntent.getBroadcast(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);

// Get the AlarmManager service 
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, dateForAlarm, sender);
于 2013-09-10T09:04:23.387 に答える