Skip to Content
Author's profile photo Midhun VP

SMP 3 – Develop App and Test

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

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.

ScreenHunter_162 Jun. 27 03.03.jpg

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

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

ScreenHunter_162 Jun. 27 03.04.jpg

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:

ScreenHunter_162 Jun. 27 03.11.jpg


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.

android screen list.png

Download Source Code


Midhun VP

@midhunvptwit

Assigned Tags

      46 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Midhun,

      Very Happy with your code and we are able to consume and display our OData from our service.

      But We are having issue with POST operation and we are using your buildPOSTRequest method in the RequestBuilder as follows

      private void postData() {

      IODataEntry entry = new ODataEntry();

      entry.putPropertyValue("BankCountry", "IN");

      entry.putPropertyValue("BankKey", "00996");

      entry.putPropertyValue("BankName", "UCUCUC");

      entry.putPropertyValue("City", "Gajuwaka");

      IRequest request = RequestBuilder.getInstance().buildPOSTRequest(this, "BankSet", entry, "$format=json");

      mApplication.getRequestManager().makeRequest(request);

      It throws Null at "mApplication.getRequestManager().makeRequest(request);"

      Here mSchema is not null in buildPOSTRequest method. Am I wrong while requesting the Server?? Please suggest me with a code snippet to solve it.

      Regards,

      Varahalu Babu Jampana

      Author's profile photo Former Member
      Former Member

      hi midhun,

      I have downloded the source code but while extracting the file is giving error. please help me out.

      SMP3 android.PNG

      thanks & regards

      jyoti sahu

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Check with Winrar.

      Author's profile photo Former Member
      Former Member

      Hi Midhun,

      Is the IP you entered here the IP for the GW server or the SMP3.0 server?

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


      Regards

      Jared

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Hi Jared,

      It is the SMP server IP.

      Regards,

      Midhun VP

      Author's profile photo Former Member
      Former Member

      Thank you Midhun.

      Continuing with the question though, am I correct in saying that if i've setup RSOE services on the SMP3.0 server to connect to the relay server I should be able to connect and register if I replaced the SMP server IP and Port with my relay servers IP and port 80?

      To setup the relay server for SMP 3.0 I followed the guide here : Configuring Relay Servers to Work with SAP Mobile Platform - Administrator - SAP Library

      The RSOE services are running and they are connected successfully to the relay server.

      Regards

      Jared

      Author's profile photo Ranjith Lingala
      Ranjith Lingala

      Hi Midhun,

      Excellent information for SMP 3.x Android native application development using SMP Native SDK 3.X. libraries.

      But in SMP 3.X SAP given user-on board using "MAF Logon" also, can you update/integrate the same application using "MAF Logon" that will be useful for everyone. Because it's new feature and every one new to "MAF Logon" for user- on boarding.

      Thanks,

      Ranjith

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Thanks Ranjith.

      I have plans to update the blog with MAFLogon and Relay server. Will update soon.

      Regards,

      Midhun VP

      Author's profile photo Ranjith Lingala
      Ranjith Lingala

      Thanks for your quick response and support Midhun.

      Regards,

      Ranjith Lingala

      Author's profile photo Former Member
      Former Member

      Thanks midhun , for a very great starting point .

      Can you suggest for the following fix when running your code ?

      "Could not find class 'com.sap.mobile.lib.request.RequestManager', referenced from method com.example.smp3android.AppInfo.getRequestManager "

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Hi Vijay,

      It should work, you just need to extract it using winrar and import to android workspace>Run. I just tested it. I am on Android API 19. The SMP libraries inside libs folder.

      Regards,

      Midhun VP

      Author's profile photo Former Member
      Former Member

      tried as mentioned in API 19 also, facing the same error

      Author's profile photo Former Member
      Former Member

      Hi vijay,            I guess you need to use "android-support-v7-appcompact" as a library project to your android project. It will available in your android installation folder..!!                                

      Author's profile photo Former Member
      Former Member

      varahalu babu jampana

      i also added the folder as a library to my android project . and facing the same error 🙁

      Author's profile photo DURAI VENKATESH
      DURAI VENKATESH

      Hi Vijay,

                    I'M using your code Develop App and Test, SMP registration is done. But I dont know how to call get request? I want read the data. pls assist me.

      Regards,

      Durai,

      Author's profile photo Juan David Lopez Gutierrez
      Juan David Lopez Gutierrez

      Hi Midhun VP,

      I need to make a GET request with filters and other request with primary key. Do you know how can I accomplish this?

      Thanks for this tutorial, It has been a great help.


      Regards,


      Juan Lopez

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Hi Juan,

      Since the endpoint URL is an Odata service you are free to use any queries/operations Odata is supported.  Ex. to use filter you have to append the filter query with the Odata service (end point url): http://services.odata.org/OData/OData.svc/Products?$filter=Rating gt 3


      Regards,

      Midhun VP

      Author's profile photo Juan David Lopez Gutierrez
      Juan David Lopez Gutierrez

      Hi Midhun,

      I append in the IRequest the filter query and this worked.

      IRequest request = RequestBuilder.getInstance().buildGETRequest(this, "Products?$filter=Rating gt 3");

      I thought I should send it as an object or other parameter.

      Thanks for your help.

      Regards,

      Juan Lopez

      Author's profile photo DURAI VENKATESH
      DURAI VENKATESH

      Hi Midun,

                    I'M using your code Develop App and Test, SMP registration is done. But I dont know how to call get request? I want read the data. pls assist me.

      Regards,

      Durai,

      Author's profile photo DineshKumar R
      DineshKumar R

      Hi Midhun,

      while initializing the application,

      in the following part

      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

      i gave the ip and port of smp server ,id and security as declared in management cockpit  and the username ,password of the odata service URL, but i am getting an error security config does not exist.

      Please Advice.

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Hi Dinesh,

      Firstly, could you please check whether you are able to register a user with SMP from a Restclient. You can refer this,SMP 3.0 : REST API Application Development

      Regards, Midhun

      SAP Customer Experience Group - CEG

      Author's profile photo DineshKumar R
      DineshKumar R

      Hi Midhun,

      Thanks for your reply.

      I have tried with the RestClient and i am able to register the user. While I tried with Android Native apps , it is showing [404]security config not found error.

      Pls help on this.

      Author's profile photo DineshKumar R
      DineshKumar R

      Hi Midhun,

      Finally identified the problem. this is because of firewall blocked. the apps successfully running and fetching data on emulator.

      Author's profile photo Juan David Lopez Gutierrez
      Juan David Lopez Gutierrez

      Hi Midhun,

      I need make a Request of type PATCH Method. I changed:

      request.setRequestMethod(IRequest.REQUEST_METHOD_PATCH);

      but, How I can send data? The Gateway Service receives a table with multiple rows.

      Do you have a tutorial where explain this process?

      Regards,

      Juan Lopez

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Hi Juan,


      Batch requests allow you to group multiple Odata requests into single HTTP request.

      GET, POST, PUT, DELETE requests can be added to a batch request. You have to manage it from the device code.

      Ex.

      private static final String ODATA_BATCH_VERB = "$batch";

      ...

      //Create the Batch Request

      BatchRequest mBatchRequest = new BatchRequest(appEndPoint + ODATA_BATCH_VERB);

      mBatchRequest.setListener(this);

      mBatchRequest.setPriority(IRequest.PRIORITY_HIGH);

      //Create the Batch Request

      mBatchRequest.addRetrieveRequestToBatch(getRequest);

      mBatchRequest.addRequestToChangeset(deleteRequest);

      mBatchRequest.addRequestToChangeset(createRequest);

      mBatchRequest.addRequestToChangeset(updateRequest);

      //Close change Requests

      mBatchRequest.closeExistingChangeSet();

      //Execute the batch request

      requestManager().makeRequest(mBatchRequest);

      Regards, Midhun

      SAP Customer Experience Group - CEG

      Author's profile photo DURAI VENKATESH
      DURAI VENKATESH

      Hi Midun,

                    I'M using your code Develop App and Test, SMP registration is done. But I dont know how to call get request? I want read the data. pls assist me.

      Regards,

      Durai,

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Hi Durai,

      A GET request was already added in the code.

      Regards, Midhun

      SAP Customer Experience Group - CEG

      Author's profile photo DURAI VENKATESH
      DURAI VENKATESH

      Hi Midhun,

                      Where did  u declared get request function in datascreen Class or Registration_Success Class. please tell me.

      Regards,

      Durai,

      Author's profile photo DURAI VENKATESH
      DURAI VENKATESH

      Hi Midhun,

                     This is the get method. But it not working, I'm getting socket handling error.

      private void getData()

      {

       

        mProgressDialog =

        ProgressDialog.show(DataScreen.this,(CharSequence) "","Loading Data",true);

        IRequest request = RequestBuilder.getInstance().buildGETRequest(this,"/CustProfile?$filter=Custid eq '0000220214'");

        mApplication.getRequestManager().makeRequest(request);

      }

      Author's profile photo DineshKumar R
      DineshKumar R

      Hi Midhun,

      1. In Android with SMP3.x , How to validate the SAP users.

      2. Since for one application there will be many odata urls, Should we configure each OData url seperately in SMP cockpit?

      please advise

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Hi Dinesh,

      You have option to add multiple backend connections while creating application in SMP 3 Admin cockpit. You can find more information here:SMP 3.0 : Accessing more than one OData services in one application

      Regards, Midhun

      SAP Customer Experience Group - CEG

      Author's profile photo DURAI VENKATESH
      DURAI VENKATESH

      Hi Midhun,

                          Here this is my get request code. when I click the getdata button, I'm getting FATAL EXCEPTION: SocketConnectionHandler #1 error and I don't know this correct or not. please assist me.


      public IRequest buildGETRequest(INetListener listener, String collection, int topFilter, String filter ) {

      String query = "";

      if (topFilter>0) query = ODATA_TOP_FILTER + topFilter;

      if (!TextUtils.isEmpty(filter)){

      if (!TextUtils.isEmpty(query)) query += "&";

      query += ODATA_FILTER + filter;

      }

      IRequest request = new BaseRequest();

      request.setListener(listener);

      request.setPriority(IRequest.PRIORITY_HIGH);

      request.setRequestMethod(IRequest.REQUEST_METHOD_GET);

      String endPointURL = mEndPoint + collection;

      //Adding the JSON format

      if (mIsJSONFormat) {

      endPointURL = endPointURL + "?" + ODATA_JSON_FORMAT;

      }

      if (!TextUtils.isEmpty(query)) {

      if(endPointURL.contains("?"))

      endPointURL = endPointURL + "&" + query;

      else

      endPointURL = endPointURL + "?" + query;

      }

      request.setRequestUrl(endPointURL);

      if (mIsMAFLogon) {

      Map<String,String> headers = new HashMap<String,String>();

      headers.put(APP_CONNECTION_ID_HEADER, mSMPAppConnectionID);

      request.setHeaders(headers);

      }

      return request;

      }


      @Override

        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,"read_cust/odt/?$filter=IKunnr eq '55556667'",schema);

        mSuccess = true;

        mHandler.post(mUpdateResults);

        }

        catch (Exception e)

        {

        e.printStackTrace();

        }

        }

      private void getData()

      {

      mProgressDialog = ProgressDialog.show(DataScreen.this,(CharSequence) "", "Loading Data", true);

      IRequest request = RequestBuilder.getInstance().buildGETRequest(this,"read_cust/?$filter=IKunnr eq '1000235'");

      mApplication.getRequestManager().makeRequest(request);

      }

      Author's profile photo DURAI VENKATESH
      DURAI VENKATESH

      Hi Midhun,

                       May I know which version of SMP did you used for that project because I'm using SMP 3 SP05. I'm downloaded that project and run in emulator when click the register button, registration is done. but next screen when click the GetData button, I'm getting Socket Handle Exception error. I dont know I'm give the input in correct place or not. please help me. below I mentioned that code please check it.

      With regards,

      Duraivenkatesh.R,

      Author's profile photo DURAI VENKATESH
      DURAI VENKATESH

      Hi Midhun,

                      Do you know about MAF Logon and how to create MAF logon class and what are the jar files needed. please help me.

      with regards,

      Duraivenkatesh.R

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Hi Durai,

      There is a how to guide available on how to use MAFLogon, http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/3086079f-6c3b-3210-c393-d18ff8ac1ed7?QuickLink=index&…

      Regards, Midhun

      SAP Customer Experience Group - CEG

      Author's profile photo DURAI VENKATESH
      DURAI VENKATESH

      Hi Midhun,

                      I followed that guide only, But now I'm facing this error

      java.lang.UnsatisfiedLinkError: Couldn't load stlport_shared from loader dalvik.system.PathClassLoader please help me.

      UnsatisfiedLinkError.png

      Author's profile photo DURAI VENKATESH
      DURAI VENKATESH

      Hi Midhun,

                             did you check that error?

      With regards,

      Duraivenkatesh.R

      Author's profile photo DURAI VENKATESH
      DURAI VENKATESH

      Hi Midhun,

                      I tried SMP3Android application registration is done. when I click the getdata button. I'm getting the SocketConnectionHandler error. I'm using SMP3 SP05 PL04.

      SocketConnectionHandler.png

      Author's profile photo DineshKumar R
      DineshKumar R

      Hi Durai,

      we are also facing the same error. are you able to find any solution.

      Author's profile photo DineshKumar R
      DineshKumar R

      Hi Midhun,

      By using the above code Registration with SMP and fetch the data from SAP are happened successfully with in corporate network.

      While trying same apps with outside network, Registration happened successfully, but not able to fetch the data from SAP.

      kindly advice.

      Author's profile photo Former Member
      Former Member

      Hi Midhun VP

      Thank you for this valuable blog.
      Can you explain how to create an HTTP Post request?

      Thanks.

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Hi Ibrahem,

      You can find an example using POST in this example,How To...Consume OData Services in Online Mode (Android)

      Regards, Midhun

      SAP Customer Experience Group - CEG

      Author's profile photo Former Member
      Former Member

      thank you 🙂

      Author's profile photo Former Member
      Former Member

      Hi Midhun,

      How to show multiple values on screen ?

      like you are showing here only Company if i have to add extra field here then what code should i use.

      BR

      Saurabh

      Author's profile photo Midhun VP
      Midhun VP
      Blog Post Author

      Hi Saurabh,

      Your question is specific to Android. You can find many examples in the web on how to have multiple values in a list item.

      Regards, Midhun

      SAP Technology RIG

      Author's profile photo Ana Velasquez
      Ana Velasquez

      Hi Midhun VP,

      At the moment I'm having a few issues with the Store concept and making a batch request, I've been recommended to update both, server and sdk to their latest version, I'm working with SDK SP05 and Server SP04, in the meantime, while these can be upgraded, I still have to make a batch request, do you think that it's possible with Request Builder, or all its methods are deprecated?

      Thanks in advance.

      Best regards,

      --

      Ana Velasquez