FAQs‎ > ‎

Taximeter API - Final Fare

posted 17 Mar 2016, 12:23 by Planet Coops   [ updated 19 Mar 2017, 05:59 ]
Where integrators have made mistakes in the past is in the way in which they've tried to capture the final fare information at the end of the ride.  Developers made assumptions that STOPPED mode indicates the end of the ride.  A transition to STOPPED does not indicate the end of the hire.  When STOPPED the meter will continue to calculate the fare based on distance only.  STOPPED mode doesn't imply END, it simply turns the time meter off.  The meter can be placed back into HIRED mode resuming the time meter.  It is only the transition from STOPPED to FOR HIRE that confirms the end of the hire.  To make it easy to detect this transition, Taximeter broadcasts an intent with extras containing the final fare information.  The correct way to pick up the values at the end of the ride (at the transition from STOPPED to FOR HIRE mode) is to register a broadcast receiver for an intent with the "com.planetcoops.intent.action.TAXIMETER_CHARGE" action which is broadcast when the ride ends, see DemoActivity.java in the Taximeter API Sample Project, e.g.

private static final String TAXIMETER_CHARGE_BROADCAST = 
                                                "com.planetcoops.intent.action.TAXIMETER_CHARGE";
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {

@Override
public void onReceive(Context context, Intent intent) {
// currency, see ITaximeterService.getCurrency()
String currency = intent.getStringExtra("currency"); //NON-NLS

/*
* !! USE THIS TECHNIQUE TO CAPTURE THE FINAL VALUES CHARGED AT THE END OF THE HIRE !!
*
* The TAXIMETER_CHARGE Intent is broadcast when a charge is made (on transition
* from STOPPED to FOR HIRE modes) and will carry the final values for the hire.
*/
if (TAXIMETER_CHARGE_BROADCAST.equals(intent.getAction())) {
// TAXIMETER_CHARGE intent
Log.i(TAG, String.format(
                    "Taximeter Charge:
\nExtras: %s%.2f\nFare: %s%.2f\nTax: %s%.2f\n" +
                    "Total: %s%.2f
\nDiscount: %s%.2f\nTip: %s%.2f\n",
currency,
intent.getDoubleExtra("chargeable_extras", 0d),
currency,
intent.getDoubleExtra("chargeable_fare", 0d),
currency,
intent.getDoubleExtra("tax", 0d),
currency,
intent.getDoubleExtra("total_fare", 0d),
currency,
intent.getDoubleExtra("discount", 0d),
currency,
intent.getDoubleExtra("tip", 0d)
));
}
<snip/>
// Receive Taximeter updates
IntentFilter filter = new IntentFilter();
filter.addAction(TAXIMETER_CHARGE_BROADCAST); // Chargeable values
registerReceiver(mReceiver, filter);