Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
midhun_vp
Active Contributor
Odata SDKSMP ConfigurationDevelop App and Test


This blog is outdated, please follow the how to guides here:Mobile Application Development Platform for Developers - Native Apps

Creating Project and Importing Libraries

Create a new Android project in eclipse > Right click on libs folder and choose Import > General > File System. Browse to Odata SDK folder . The Odata SDK can be found inside the SMP SDK as given below.

Choose the below libraries from column on the right and click on Finish.

Common, Connectivity, Coreservices, gson, Parser, perflib, Request and sap-e2etrace.

Right click on the project and choose Build path > Configure Build Path, click on Libraries tab, then click on Add Jars. Select the project created from the list and go inside libs folder and choose all the jar files and click on OK.

Project after adding jar files:


Initialize application

Login.java class will be called first in the project. The application has to be initialized when it starts first time.

Clientconnection parameters has to be set before registration. You can find the App ID and security name in the code below, that was created during SMP configuration.

String returnMsg = "success";

  try

        {

  mApplication.setUsername("P0000000000");

  mApplication.setPassword("Initial123");

  ClientConnection clientConnection =

  new ClientConnection(getApplicationContext(),

  "com.test.android",

  null,

  "SAPSecurity",

  mApplication.getRequestManager());

  clientConnection.setConnectionProfile(true, "66.175.100.29", "8080", null, null);

         UserManager userManager = new UserManager(clientConnection);

         userManager.registerUser(true); //Registering user

Creating Request

After successful registration the control goes to the Registration_Success class. The service document and schema are accessed in this class. The Request manager makes HTTP requests to server. The requests are asynchronous, hence listeners to get the response. If the response of the request is success Onsuccess method is called else onError method.

public void onSuccess(IRequest aRequest, IResponse aResponse) {

  try {

  HttpEntity responseEntity = aResponse.getEntity();

  String responseString = EntityUtils.toString(responseEntity);

  Parser parser = mApplication.getParser();

  if (aRequest.getRequestTAG().contentEquals(REQUEST_SERVICE_DOCUMENT)) {

  mServiceDocument = parser.parseODataServiceDocument(responseString);

  } else if (aRequest.getRequestTAG().contentEquals(REQUEST_METADATA)) {

  IODataSchema schema = parser.parseODataSchema(responseString, mServiceDocument);

  mApplication.setODataSchema(schema);

  RequestBuilder.getInstance().setSchema(schema);

  }

  mSuccess = true;

  mHandler.post(mUpdateResults);

  } catch (ParseException e) {

  } catch (IOException e) {

  } catch (IllegalArgumentException e) {

  } catch (ParserException e) {

  }

public void onError(IRequest aRequest, IResponse aResponse,

  IRequestStateElement aRequestState) {

  //Post to UI Thread

  mSuccess = false;

  mHandler.post(mUpdateResults);

  }

  }

Parsing Data

In the DataAccess class a request is made with the collection ID "BusinessPartnerCollection" to retrieve the data based on a particular collection ID (In a browser it can be teste using the URL http://sapes1.sapdevcenter.com:8080/sap/opu/odata/iwbep/gwdemo/BusinessPartnerCollection).

Retrieve the data from the response using the parser.

public void onSuccess(IRequest aRequest, IResponse aResponse) {

  try {

  HttpEntity responseEntity = aResponse.getEntity();

  String responseString = EntityUtils.toString(responseEntity);

  Parser parser = mApplication.getParser();

  IODataSchema schema =mApplication.getODataSchema();

Entries = parser.parseODataEntries(responseString, "BusinessPartnerCollection", schema);// Parsing Data

  mSuccess = true;

  mHandler.post(mUpdateResults);

  } catch (Exception e) {

  e.printStackTrace();

  }

  }

The value of the property can be accessed using the below code:

List poset = new ArrayList();

for(IODataEntry entry:Entries)

    {

           String Street = entry.getPropertyValue("Company").toString();// Company is a property in Odata

           poset.add(Street);

    }

The property "Company" is populated in a list view in Android.

Download Source Code


Midhun VP

@midhunvptwit

46 Comments
Labels in this area