package com.example.location;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.location.LocationManager;

public class ProximityAlertBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        boolean entering = intent.getBooleanExtra(
                LocationManager.KEY_PROXIMITY_ENTERING, true);
        if (entering) {
            NotificationManager nm = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);

            Resources resources = context.getResources();
            int icon = R.drawable.ic_launcher;
            String title = resources.getString(R.string.notifTitle);
            String ticker = resources.getString(R.string.notifTicker);
            String text = resources.getString(R.string.notifText);
            long when = System.currentTimeMillis();
            int id = 12345;

            //Notification n = new Notification(icon, ticker, when);
            //n.setLatestEventInfo(context, title, text, null);
            Notification.Builder builder = new Notification.Builder(context)
              .setContentTitle(title)
              .setTicker(ticker)
              .setContentText(text)
              .setSmallIcon(icon)
              .setWhen(when);
            nm.notify(id, builder.build());
        }
    }
}
