Odata SDK | SMP Configuration | Develop App and Test |
This blog is outdated, please follow the how to guides here:Mobile Application Development Platform for Developers - Native Apps
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:
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
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);
}
}
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.
Midhun VP
@midhunvptwit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 |