18 Replies Latest reply: Dec 5, 2013 9:19 PM by Prateek Aggarwal RSS

Access data from MBO from native Android application

Atmaram Thakur
Currently Being Moderated

HI All,

i have been trying to use the generated Android code for a deployed MBO from a native android application.

 

the step  followed is as follows :

1. MBO created using a SAP BAPI ( BAPI_FLIGHT_GETLIST)

2. deployed it into the unwired server

3. generated the code

4. copied the code to a Android project

5. used the generated code to access the data from MBO using the following steps

     i)     Set application details

            Application app = Application.getInstance();

            app.setApplicationIdentifier("FlightSearch");

            app.setApplicationContext(<android context>);

            FlightSearchDB.setApplication(app);

     ii)  Set authentication credentials

            ConnectionProperties connProps = app.getConnectionProperties();

            LoginCredentials loginCredentials = new LoginCredentials(USERNAME, PASSWORD);

 

            connProps.setLoginCredentials(loginCredentials);

            connProps.setServerName(HOST);

            connProps.setPortNumber(PORT);

     iii) register connection

           if (app.getRegistrationStatus() != RegistrationStatus.REGISTERED)

            {

                app.registerApplication(TIMEOUT);

            }

            else

            {

                app.startConnection(TIMEOUT);

            }

 

     iv) Set sync parameter

           ConnectionProfile profile = FlightSearchDB.getSynchronizationProfile();

            profile.setServerName(HOST);

            profile.setPortNumber(2480);

            profile.setNetworkProtocol("http,https");

            profile.setDomainName("default");

            profile.setAsyncReplay(true);

            profile.save();

     v) start sync

          FlightSearchDB.synchronize(new MySyncStatusListener());

 

i can see the status in objectSyncStatus() method of MySyncStatusListener.

initially it tried to upload data , since no local data is there for the first run it sends some null values and then wait for the ack from server. I get APPLICATION_SYNC_RECEIVING_UPLOAD_ACK status for  a long time and never get a ack from server hence data sync goes in to a dead lock.

 

In the mean time i tried to check the server logs and it shows :

2012-06-21 02:03:26.135 CONSOLE MMS pool-1-thread-18 - /registration/RegistrationServlet [com.sybase.sup.server.Console]6146

2012-06-21 02:03:25.491 CONSOLE MMS pool-1-thread-16 - /registration/RegistrationServlet [com.sybase.sup.server.Console]6038

 

If i disable the sync part of the code, i can run the following code but the result is always 0 which is obvious, since there will be no local data available without sync.

     vi) Access Database

           if(!FlightSearchDB.databaseExists()){

                FlightSearchDB.createDatabase();

            }

            FlightSearchDB.openConnection();

 

            GenericList<Flight> flights = Flight.findAll();

 

 

Can anybody let me know, if there is any issu with the code / configuration issue which i need to resolve to aces the data.

 

Regards,

Atmaram

  • Re: Access data from MBO from native Android application
    Daniel Yrigoyen
    Currently Being Moderated

    Hello Atmaram,

     

    I had some connection problem with Native Blackberry App, i know that is not android, but in the way of resolving my problem, i found this article about an android connection, so... hope that can help you.
    http://scn.sap.com/community/mobile/blog/2012/05/02/sup-212-native-android-mbo-non-doe-based-approach-through-rs

     

    Regards,
    Daniel

  • Re: Access data from MBO from native Android application
    Gachoud Emilie
    Currently Being Moderated

    Hello Atmaram,

     

    have you found solutions?

     

    Thank's...

     

    Emilie

  • Re: Access data from MBO from native Android application
    Lakshminarayanan V
    Currently Being Moderated

    Hi Atmaram

     

    First could you please let us know the versions of Android and the SUP server?

     

    Next I assume the port you are setting after the Login Credentials is 5001. Are you getting registered in the SCC?

     

    Last to access database you do not have to open connection if you are successfully registered. The API does it for you.

     

    regards

     

    elenwe

  • Access data from MBO from native Android application
    Atmaram Thakur
    Currently Being Moderated

    Hi

    the problem is solved.

     

    i followed the example given in sup site. (http://scn.sap.com/docs/DOC-8803)

    the problem was not with the code but the server configuration and the user profile that i was using in the emulator.

     

    Regards,

    Atmaram

  • Re: Access data from MBO from native Android application
    Gachoud Emilie
    Currently Being Moderated

    Ok thank you. But I think the tutorial is not clear ... you put this code and your application run? can you send me an example? pleeeeeeaaaassssseeeee

     

     

    Regards,

     

     

    Emilie

    • Re: Access data from MBO from native Android application
      Atmaram Thakur
      Currently Being Moderated

      i am using the following code:

      try {

               // 1. App initialization

                  Application app = Application.getInstance();

                  app.setApplicationIdentifier("FlightSearch");

                  app.setApplicationContext(MyActivity.this);

                 

       

                  FlightSearchDB.setApplication(app);

                  FlightSearchDB.getSynchronizationProfile().setServerName(HOST); // Convenience

                                                                                  // only

                // 2. Set connection properties

                  ConnectionProperties connProps = app.getConnectionProperties();

                  LoginCredentials loginCredentials = new LoginCredentials(USERNAME,

                          PASSWORD);

                  connProps.setLoginCredentials(loginCredentials);

                  connProps.setServerName(HOST);

                  connProps.setPortNumber(PORT);

                 

                //3. App registration

                  if (app.getRegistrationStatus() != RegistrationStatus.REGISTERED) {

                      app.registerApplication(TIMEOUT);

                  } else {

                      app.startConnection(TIMEOUT);

                  }

       

                 

                 //4. Sync data           

                  if (!FlightSearchDB.isSynchronized("default")) {

                     

                      FlightSearchDB.disableChangeLog();

                      FlightSearchDB.synchronize(); // Initial Synchronize

       

                     

                      SynchronizationGroup sg = FlightSearchDB

                              .getSynchronizationGroup("default");

                      sg.setEnableSIS(true);

                      sg.save();

                      FlightSearchDB.synchronize();

                  }

                  FlightSearchDB.enableChangeLog();

              }catch (SynchronizeException e){

                  System.out.println("Exception1 " + e);

                  System.out.println("Cause "+e.getCause());

                  System.out.println("Msg "+e.getMessage());

                  e.printStackTrace();

              }

              catch (Exception e) {

                  System.out.println("Exception2 " + e);

                  e.printStackTrace();

       

              } finally {

                  //initializationDone = true;

              }

             

       

                //5. Fetch data

              GenericList<Flight> flights = Flight.findAll();

              System.out.println("Size "+flights.size());

       

      Using this i am getting the flight count.

       

      I have not given details of MBO creation and code generation since that is the standard process which you can follow.

       

      Hope this helps you.

      • Re: Access data from MBO from native Android application
        Gachoud Emilie
        Currently Being Moderated

        Thank you very much!!!!

         

        Emilie

      • Re: Access data from MBO from native Android application
        Gachoud Emilie
        Currently Being Moderated

        I have another question "connection properties" is the connection to connect to relay server or SAP?... When the application wants to connect LogCat return error...

         

         

        Thank's

         

         

         

        Emilie

        • Re: Access data from MBO from native Android application
          Atmaram Thakur
          Currently Being Moderated

          Itss the SUP server. In my case i have given

          host as ip address of SUP server.

          port as 5001

          timeout as 600

           

          can you port the error u are getting in logcat.

          • Re: Access data from MBO from native Android application
            Gachoud Emilie
            Currently Being Moderated

            this is my code:

             

            public class MainActivity extends Activity {

            private int lowIndex = 0; //0
                private int highIndex = 0; //40 = 39+1
                private static final String NAME = "name";
                private LayoutInflater layoutInflater;
                private ArrayList<HashMap<String, Object>> loadedCustomer;
                private static final int REQUEST_DETAIL = 99;
                //private static String USERNAME = "samsung";
                //private static String PASSWORD = "123";
                private static String HOST = "****";
                private static int PORT = 80;
                private static int TIMEOUT = 600;
               Application app = Application.getInstance();


                private static boolean initializationDone = false;

             

                @Override
                public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_main);

                
                }

                @Override
                public boolean onCreateOptionsMenu(Menu menu) {
                    getMenuInflater().inflate(R.menu.activity_main, menu);
                    return true;
                }

                private void initializeApplication(){
              try{
                  // initialisation de l'application
                   app = Application.getInstance();
                 app.setApplicationIdentifier("cat");
                 app.setApplicationContext(MainActivity.this);
                 CatDB.setApplication(app);
                 CatDB.getSynchronizationProfile().setServerName(HOST);
               
             
                   // Propriétés de connexion
                 ConnectionProperties connProps = app.getConnectionProperties();
                // LoginCredentials loginCredentials = new LoginCredentials(USERNAME, PASSWORD);
                 //connProps.setLoginCredentials(loginCredentials);
                 connProps.setServerName(HOST);
                 connProps.setPortNumber(PORT);
                 connProps.setFarmId("***");
                 connProps.setUrlSuffix("/ias_relay_server/client/rs_client.dll");
                
                

                
                // enregistrement de l'application
                 if (app.getRegistrationStatus()!=RegistrationStatus.REGISTERED){
                  app.registerApplication(TIMEOUT);
                 } else {
                  app.startConnection(TIMEOUT);
                 }
                
                 // synchronisation des données
                 if (!CatDB.isSynchronized("default")){
                  CatDB.disableChangeLog();
                  CatDB.synchronize();
                  SynchronizationGroup sg = CatDB.getSynchronizationGroup("default");
                  sg.setEnableSIS(true);
                  sg.save();
                  CatDB.synchronize();
                 }
                 CatDB.enableChangeLog();
                }catch (SynchronizeException e){
                 System.out.println("Exception 1"+ e);
                 System.out.println("Cause" +e.getCause());
                 System.out.println("Msg"+e.getMessage());
                 e.printStackTrace();
                
                }catch (Exception e){
                 System.out.println("Exception 2"+e);
                 e.printStackTrace();
                }finally{
                 initializationDone= true;
                }

               GenericList<CatGetDetail> catGetDetails= CatGetDetail.findAll();
              System.out.println("Size" +catGetDetails.size());
                }
            }

             

             

             

            When I run the application it is a blank page...There are no errors. I am using Sybase 2.1.2. and android 4.0.3.

      • Re: Access data from MBO from native Android application
        lutiaud sébastien
        Currently Being Moderated

        Hi Atmaram,

         

        Can you put your final code and explain how you use it and where? (MainActivity.java? In a function?). What is "FlightSearchDB"?

         

        Thank,

  • Re: Access data from MBO from native Android application
    Pratik Gandhi
    Currently Being Moderated

    How to use synchronization and load parameter in same application . I am getting flight list , But now i want to use some personalization key  - source and destination ..how to do that ?

Actions