How to Extend Your Android App to Include SMS-based Shipment Tracking

How to Extend Your Android App to Include SMS-based Shipment Tracking

TaCode Tuesday is back!  That means your favorite developer at Zang is here to deliver free snippets of code for use in your very own text/voice apps along with hilarious taco puns. This week I’m going to show you how to make e-commerce customers smile by allowing them to track deliveries via SMS on their Android phone. But first, let’s taco ’bout how this can set your business apart and improve customer loyalty.

In most cases, products are cheaper when ordered online. When compared to retail, online products are more or less 50 percent cheaper due to the elimination of certain components that hike up product prices like storage, rent, staff, utilities, and the middle-man.
E-commerce has come a long way since the 2001 dot-com boom. In fact, cross-border e-commerce is a growing phenomenon. In Nielsen’s 2016 global report, survey data showed that 57 percent of consumers have purchased something from an online store outside their country for the past six months. Italians are the most receptive at 79 percent, followed by Germans at 73 percent, and Russians at 64 percent.
The figure below shows how much shoppers around the world have purchased internationally through an ecommerce platform.

Figure 1: Nielsen’s Global Report of Cross-border Commerce Adoption

Challenges of Cross Border Commerce

Cross-border commerce’s high adoption rate can be attributed to the new-found freedom of access to a world of products that were previously unavailable to a consumer’s home country. As Nielsen said:
“Choice is greatly enhanced by cross-border e-commerce. In many developing markets, the growing middle class is trading up and demanding greater assortment than found at their domestic retailer. For example, some of these consumers are looking overseas to purchase authentic foreign brands, often at lower prices than they can find in their home country. Meanwhile, developed-market consumers gain access to a range of goods directly from foreign companies at often significant discounts to what they would pay domestically”
However, logistics and reverse logistics are a challenge when conducting a successful cross-border e-commerce. Effective logistics is key not only to a successful online business, but retail business as well. Shipping costs, reliability, and predictability can be a tipping point if not handled correctly.


Shipping and Customer Satisfaction

An e-commerce business’ role in customer satisfaction doesn’t stop the moment the product is handed over to the courier. Customers believe that it is still the business’ responsibility to assure that the products are delivered on time and in good condition. Not only this, returns and exchanges should also be easy with the costs of returns, custom duties, and documentation kept at a minimum, if not for free.


SMS-based Shipment Tracking

This week, we will teach you how to create an SMS-based shipment tracking that could help improve customer satisfaction in cross-border transactions. We will be developing this for Android since this mobile OS has dominated the smartphone market.
Before starting, you must at least have an intermediate knowledge of:<

  • Java
  • SOAP Web Services
  • KSOAP2 Library for handling SOAP enabled web services
  • Zang SMS API
  • A

The architecture is quite simple. Once an order is placed via an Android phone, a pop-up is displayed asking the customer if he or she wants to receive real-time shipping updates via SMS. Once agreed, every time a shipping milestone is reached, your application server will call the Zang SMS API to send out the shipping status update to your customer’s pre-defined number which is eventually pushed to his or her respective network provider regardless of country.

Figure 2: SMS-Based Shipment Tracking

Let’s start coding!

Step 1: Request access to your shipping provider’s API, which allows you to have a real-time update of the shipment as soon as it is reflected in their systems. Alternatively, a daily file extract of shipping status can be pushed to you by the courier that you can consequently send to your customers before end of day. Perhaps a quick work-around (though this should only be temporary), is to have staff who can check at the end of day in bulk the status of each shipment, until the viability of the solution is proven for a wider-scale implementation. For this tutorial, let us assume though that we will be using FedEx as a courier partner. FedEx has a developer API that can be used if you want to integrate its functionality to your website or application.

Step 2: Craft generic shipping milestone messages that you can map to the existing status messages of your respective shipping providers, like FedEx. Below is an example:

Figure 3: A sample shipping milestones
These shipping milestone messages will be sent out to customers via SMS to show where their products are. Alternatively, you can use the exact tracking message that you can pull from the FedEx API. The advantage of sending shipping milestone messages is that it will limit the amount of SMS that you send per customer hence making this added feature more cost-efficient.

Step 3: Connect to FedEx Developer WSDL/Soap web services. Below is an example of a soap envelope tracking request. In using the FedEx API, you have the option to request status one by one or in bulk. Below is a sample of requesting shipping status per shipment.<soapenv:Envelope xmlns:soapenv=””xmlns:v10=”″><soapenv:Header/>























<v10:CustomerTransactionId>Ground Track By

























Step 4: Install KSOAP2 Library and add it to your Android project then write your Android code that will connect to the SOAP web service of your third-party Courier provider.

import android.os.Bundle;


import android.util.Log;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;


import org.ksoap2.SoapEnvelope;

import org.ksoap2.serialization.SoapObject;

import org.ksoap2.serialization.SoapPrimitive;

import org.ksoap2.serialization.SoapSerializationEnvelope;

import org.ksoap2.transport.HttpTransportSE;



public class MainActivity extends ActionBarActivity



String TAG = “Response”;

Button bt;

EditText celcius;

String getCel;

SoapPrimitive resultString;



protected void onCreate(Bundle savedInstanceState) {




bt = (Button) findViewById(;

celcius = (EditText) findViewById(;



bt.setOnClickListener(new View.OnClickListener() {


public void onClick(View view) {


getParcelData = trackParcel.getText().toString();

AsyncCallWS task = new AsyncCallWS();






private class AsyncCallWS extends AsyncTask<Void, Void, Void> {



protected void onPreExecute() {

Log.i(TAG, “onPreExecute”);




protected Void doInBackground(Void… params) {

Log.i(TAG, “doInBackground”);


return null;




protected void onPostExecute(Void result) {

Log.i(TAG, “onPostExecute”);

Toast.makeText(MainActivity.this, “Response” + resultString.toString(), Toast.LENGTH_LONG).show();





public void tracking()




String NAMESPACE = “{}”;

String URL = “{}”;


try {

SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

Request.addProperty(“TrackingStatus”, getCel);


SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

soapEnvelope.dotNet = true;



HttpTransportSE transport = new HttpTransportSE(URL);, soapEnvelope);

resultString = (SoapPrimitive) soapEnvelope.getResponse();


Log.i(TAG, “TrackingStatusResult: ” + resultString);

} catch (Exception ex) {

Log.e(TAG, “Error: ” + ex.getMessage());




Step 5: Write the code for the pop-up message asking the customer if he wanted to have shipping updates via SMS. You will insert this code into your existing Android app to have a sort of opt-in feature for your users to receive SMS.

AlertDialog.Builder builder1 = new AlertDialog.Builder(context);

builder1.setMessage(“Do you want to receive SMS tracking notification for your package?





new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int id) {


// Add handler for Yes

// Goto Step 5





new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int id) {


//Add handler for No



AlertDialog alert11 = builder1.create();;

Step 5: Write the code to call Zang SMS API to send the shipping status every time FedEx posts shipping update.

public void postData()


// Create a new HttpClient and Post Header

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new


try {

//milestones reached

if ( var milestone == true ) {

// Add your data

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);

nameValuePairs.add(new BasicNameValuePair(“To”, “XXX-XXX-XXXX”));

nameValuePairs.add(new BasicNameValuePair(“From”, “XXX-XXX-XXXX”));

nameValuePairs.add(new BasicNameValuePair(“Body”, “This is an SMS sent from


httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request

HttpResponse response = httpclient.execute(httppost);


catch (ClientProtocolException e) {

// TODO Auto-generated catch block

} catch (IOException e) {

// TODO Auto-generated catch block




//Successful result in JSON format after call to postData


“api_version”: “v2”,

“sid”: “{SmsSid}”,

“account_sid”: “{AccountSid}”,

“date_created”: “Tue, 24 Jul 2012 14:08:23 +0000”,

“date_updated”: “Tue, 24 Jul 2012 14:08:24 +0000”,

“date_sent”: “Tue, 24 Jul 2012 14:08:24 +0000”,

“to”: “+17325551234”,

“from”: “+14245551234”,

“body”: “Test message sent from TelAPI!”,

“status”: “sent”,

“direction”: “outbound-api”,

“price”: “0.070000”,

“uri”: “/v2/Accounts/AC5521767e53d04deeb0a06f660cee50f9/SMS/Messages/{SmsSid}.json”


That’s it!
Using SMS-based shipment tracking is an effective way to increase customer satisfaction that could eventually turn into customer loyalty. Once this state is reached, typical customers can become brand ambassadors that can promote your e-commerce business to their family, friends, and peers transforming them to so-called zombie loyalists– the type of customer that characterizes the patrons of some of the most successful brands, like Apple. Want more ideas on how to improve business processes with Zang? Check out this $100 SMS Marketing Campaign.

Views All Time
Views All Time
Views Today
Views Today