Hello friends that I developed an application Creating courses. I want to give notice when the time course.
So if you have classes Monday at 8 o'clock. 8 hours per week of class time came. I want to create a notification. I'm doing this with the alarmmanager and notification. I can give you one-time alarms. But somehow I could not repeat. Codes as follows. I will not try it because it is part of recevice.
private void alarmla() {
SQLiteDatabase db=activity.openOrCreateDatabase("SINIFD",activity.MODE_PRIVATE,null);
Cursor c = db.rawQuery("select * from ders", null);
if(c.getCount()>0){
c.moveToFirst();
do {
AlarmManager alarmManager = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
Toast.makeText(activity, c.getString(3).split(":")[0] + " " + c.getString(3).split(":")[1], Toast.LENGTH_LONG).show();
Intent notificationIntent = new Intent("android.media.action.DISPLAY_NOTIFICATION");
notificationIntent.addCategory("android.intent.category.DEFAULT");
notificationIntent.putExtra("message", c.getString(1) + " dersi zamanı geldi. Kazanımlara ulaşmak için tıklayınız. İyi dersler.");
notificationIntent.putExtra("gizli", c.getString(6));
PendingIntent broadcast = PendingIntent.getBroadcast(activity, c.getInt(0), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar timeOff = Calendar.getInstance();
int days = Calendar.FRIDAY + (7 - timeOff.get(Calendar.DAY_OF_WEEK)); // how many days until Sunday
timeOff.add(Calendar.DATE, days);
timeOff.set(Calendar.HOUR, Integer.parseInt(c.getString(3).split(":")[0])); //buraya 22 geliyor databaseden
timeOff.set(Calendar.MINUTE,Integer.parseInt(c.getString(3).split(":")[1])); //buraya 10 geliyor mesala
timeOff.set(Calendar.SECOND, 0);
timeOff.set(Calendar.MILLISECOND, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, timeOff.getTimeInMillis(),AlarmManager.INTERVAL_DAY * 7, broadcast);
} while (c.moveToNext());
c.close();
}
db.close();
Toast.makeText(activity,"Vay be ayar ",Toast.LENGTH_LONG).show();
}
When there is no problem with the database of the adjustment.