Skip to Content

SMP 3 – 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

46 Comments
You must be Logged on to comment or reply to a post.
  • 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

  • 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

  • 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

      • 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

      • 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

  • 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 “

    • 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

        • 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..!!                                

          • 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,

  • 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

      • 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

      • 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,

  • 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.

  • 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

    • 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

  • 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,

      • Hi Midhun,

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

        Regards,

        Durai,

      • 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);

        }

  • 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

  • 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);

    }

  • 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,

  • 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

  • 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.

  • 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

    • 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

  • 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