/* * This file is part of Find Your Friend. * * Find Your Friend is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Find Your Friend is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Find Your Friend. If not, see <http://www.gnu.org/licenses/>. */ package com.sgu.findyourfriend.service; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.SystemClock; import android.preference.PreferenceManager; public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent arg1) { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(context); int minutes = prefs.getInt("interval", 1000); AlarmManager am = (AlarmManager) context .getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(context, ServiceUpdatePosition.class); PendingIntent pi = PendingIntent.getService(context, 0, i, 0); am.cancel(pi); if (minutes > 0) { am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + minutes * 60 * 1000, minutes * 60 * 1000, pi); } } }