You can integrate Apigee features into your app by including the SDK in your project. You can do one of the following:
If you've already got an Android project, you can integrate the Apigee SDK into your project as you normally would:
Add
apigee-android-<version>.jar
to your class path by doing the following:
Copy the jar file into the
/libs
folder in your project.
apigee-android-<version>.jar
,
then click Open.
apigee-android-<version>.jar
at the top of the class path:
IMPORTANT: Select the checkbox for
apigee-android-<version>.jar
, then click the Top button.
If you are using Ant to build your application, you must also
copy
apigee-android-<version>.jar
to the
/libs
folder in your application.
Add the following Internet permissions to your application's
AndroidManifest.xml
file if they have not already been added. Note that with the exception
of INTERNET, enabling all other permissions are optional.
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
To initialize the App Services SDK, you must instantiate the
ApigeeClient
class. There are multiple ways to handle this step, but we recommend
that you do the following:
Application
class, and add an
instance variable for the ApigeeClient
to it, along
with getter and setter methods. public class YourApplication extends Application { private ApigeeClient apigeeClient; public YourApplication() { this.apigeeClient = null; } public ApigeeClient getApigeeClient() { return this.apigeeClient; } public void setApigeeClient(ApigeeClient apigeeClient) { this.apigeeClient = apigeeClient; } }
Application
subclass in your AndroidManifest.xml
.
For example: <application> android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name=".YourApplication" … </application>
ApigeeClient
class in the onCreate
method of your first Activity
class: import com.apigee.sdk.ApigeeClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String ORGNAME = "{{currentOrg}}"; String APPNAME = "{{currentApp}}"; ApigeeClient apigeeClient = new ApigeeClient(ORGNAME,APPNAME,this.getBaseContext()); // hold onto the ApigeeClient instance in our application object. YourApplication yourApp = (YourApplication) getApplication; yourApp.setApigeeClient(apigeeClient); }
This will make the instance of
ApigeeClient
available to your
Application
class.
The following classes will enable you to call common SDK methods:
import com.apigee.sdk.data.client.DataClient; //App Services data methods import com.apigee.sdk.apm.android.MonitoringClient; //App Monitoring methods import com.apigee.sdk.data.client.callbacks.ApiResponseCallback; //API response handling import com.apigee.sdk.data.client.response.ApiResponse; //API response object
Once initialized, App Services will also automatically instantiate the
MonitoringClient
class and begin logging usage, crash and error metrics for your app.
To verify that the SDK has been properly initialized, run your app, then go to 'Monitoring' > 'App Usage' in the App Services admin portal to verify that data is being sent.
The
DataClient
and
MonitoringClient
classes are also automatically instantiated for you, and
accessible with the following accessors:
DataClient dataClient = apigeeClient.getDataClient();
Use this object to access the data methods of the App Services SDK, including those for push notifications, data store, and geolocation.
MonitoringClient monitoringClient = apigeeClient.getMonitoringClient();
Use this object to access the app configuration and monitoring methods of the App Services SDK, including advanced logging, and A/B testing.
With App Services you can quickly add valuable features to your mobile or web app, including push notifications, a custom data store, geolocation and more. Check out these links to get started with a few of our most popular features:
The SDK includes samples that illustrate Apigee features. You'll find the samples in the following location in your SDK download:
apigee-android-sdk-<version> ... /samples
The samples include the following:
Sample | Description |
---|---|
books | An app for storing a list of books that shows Apigee database operations such as reading, creating, and deleting. |
messagee | An app for sending and receiving messages that shows Apigee database operations (reading, creating). |
push | An app that uses the push feature to send notifications to the devices of users who have subscribed for them. |