package com.example.patrice.repeat_request_02;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        setRepeatingAlarm();
    }

    public void setRepeatingAlarm()
    {
        //Intent intent = new Intent(this, TimeAlarm.class);
        //PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,    intent, PendingIntent.FLAG_CANCEL_CURRENT);
        //am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),   (10 * 1000), pendingIntent);

        //2*60*60

        Intent intent = new Intent(this, Notification.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 12345, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        AlarmManager am =  (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
        am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(),  2*60*60,pendingIntent);

    }
}
