package com.example.patrice.appli_02;

import android.app.AlarmManager;
import android.app.IntentService;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * Created by Patrice on 02/05/2018.
 */

public class AlarmService extends IntentService
{

    private static final String TAG = "AlarmService";

    public AlarmService()
    {
       super(TAG);
       String a = "5";

    }


    @Override
    protected void onHandleIntent(Intent intent)
    {

        int a = 1;
        definir();

    }

    public void definir()
    {
        Intent i;
        int s = 60;
        int keycode = 1;


        AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

        i = new Intent(this, AlarmReceiver.class);

        PendingIntent pi = PendingIntent.getBroadcast( this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
//        pi =               PendingIntent.getBroadcast(this, (int) keycode, i, PendingIntent.FLAG_UPDATE_CURRENT);

        am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), pi); // now
        am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (s * 1000), pi);

        Log.v("*********", "Config alarm manager");


    }

}
