List of usage examples for android.location LocationManager removeProximityAlert
public void removeProximityAlert(PendingIntent intent)
From source file:uk.org.rivernile.edinburghbustracker.android.alerts.ProximityAlertReceiver.java
/** * {@inheritDoc}/*from w ww .j ava 2 s .c om*/ */ @Override public void onReceive(final Context context, final Intent intent) { final SettingsDatabase db = SettingsDatabase.getInstance(context); final String stopCode = intent.getStringExtra(ARG_STOPCODE); // Make sure the alert is still active to remain relevant. if (!db.isActiveProximityAlert(stopCode)) return; final String stopName = BusStopDatabase.getInstance(context).getNameForBusStop(stopCode); final NotificationManager notMan = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); final LocationManager locMan = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // Delete the alert from the database. db.deleteAllAlertsOfType(SettingsDatabase.ALERTS_TYPE_PROXIMITY); // Make sure the LocationManager no longer checks for this proximity. final PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); locMan.removeProximityAlert(pi); final String title = context.getString(R.string.proxreceiver_notification_title, stopName); final String summary = context.getString(R.string.proxreceiver_notification_summary, intent.getIntExtra(ARG_DISTANCE, 0), stopName); final String ticker = context.getString(R.string.proxreceiver_notification_ticker, stopName); final SharedPreferences sp = context.getSharedPreferences(PreferencesActivity.PREF_FILE, 0); // Create the notification. final NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context); notifBuilder.setAutoCancel(true); notifBuilder.setSmallIcon(R.drawable.ic_status_bus); notifBuilder.setTicker(ticker); notifBuilder.setContentTitle(title); notifBuilder.setContentText(summary); // Support for Jelly Bean notifications. notifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(summary)); final Intent launchIntent; if (GenericUtils.isGoogleMapsAvailable(context)) { // The Intent which launches the bus stop map at the selected stop. launchIntent = new Intent(context, BusStopMapActivity.class); launchIntent.putExtra(BusStopMapActivity.ARG_STOPCODE, stopCode); } else { launchIntent = new Intent(context, BusStopDetailsActivity.class); launchIntent.putExtra(BusStopDetailsActivity.ARG_STOPCODE, stopCode); } notifBuilder .setContentIntent(PendingIntent.getActivity(context, 0, launchIntent, PendingIntent.FLAG_ONE_SHOT)); final Notification n = notifBuilder.build(); if (sp.getBoolean(PreferencesActivity.PREF_ALERT_SOUND, true)) n.defaults |= Notification.DEFAULT_SOUND; if (sp.getBoolean(PreferencesActivity.PREF_ALERT_VIBRATE, true)) n.defaults |= Notification.DEFAULT_VIBRATE; if (sp.getBoolean(PreferencesActivity.PREF_ALERT_LED, true)) { n.defaults |= Notification.DEFAULT_LIGHTS; n.flags |= Notification.FLAG_SHOW_LIGHTS; } // Send the notification to the UI. notMan.notify(ALERT_ID, n); }