Skip to Content
0
Former Member
Nov 18, 2013 at 05:43 PM

registering device in scc for android native using oData

33 Views

Hi Experts,

am trying to develop native android app using oData restful service.

am not able to register the the device in scc.

am following this tutorial.created a security configuration and aplication id in scc.

am using 30 days evalution trail sup platform.

http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc01975.0224/doc/pdf/sup_tutorial_android_odata_application_development_with_rest_services.pdf

public class MainActivity extends Activity implements ISMPUserRegistrationListener {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

connectionMethod();

}

void connectionMethod(){

try{

Utilities.initializeRequestManager(getApplicationContext());

Utilities.clientConnection = new ClientConnection(getApplicationContext(), Utilities.appId, Utilities.domain, Utilities.secConfig,Utilities.reqMan);

Utilities.userManager = new UserManager(Utilities.clientConnection);

Utilities.appSettings = new AppSettings(Utilities.clientConnection);

if(Utilities.isHttpRequest ){

Utilities.clientConnection.setConnectionProfile(Utilities.isHttpRequest,Utilities.host,Utilities.port, null,null);

System.out.println("connection:::::::::");

}

else{

Utilities.clientConnection.setConnectionProfile(false,Utilities.host,Utilities.port, null,null);

System.out.println("conneion:::::::::");

}

Utilities.userManager.setUserRegistrationListener(MainActivity.this);

Utilities.userManager.registerUser(false);

}

catch(Exception e){

Toast toast = Toast.makeText(getApplicationContext(), "Failed to connect!", Toast.LENGTH_LONG);

toast.show();

}

}

public void onAsyncRegistrationResult(State registrationState, ClientConnection clientConnection, int errCode, String errMsg) {

try{

if(registrationState==State.SUCCESS){

MainActivity.this.runOnUiThread(new Runnable() {

public void run() {

Toast.makeText(getApplicationContext(), Utilities.userName +" registered successfully.", Toast.LENGTH_LONG).show();

}

});

}

else{

Log.i("SMP", " Error code " + errCode + " error message " + errMsg);

MainActivity.this.runOnUiThread(new Runnable() {

public void run() {

Toast.makeText(getApplicationContext(), Utilities.userName +" registrfailed!", Toast.LENGTH_LONG).show();

}

});

}

}catch(Exception e){

MainActivity.this.runOnUiThread(new Runnable() {

public void run() {

Toast.makeText(getApplicationContext(), Utilities.userName +" reg failed!", Toast.LENGTH_LONG).show();

}

});

e.printStackTrace();

}

}

}

-----------------------------------------------

public class Utilities {

// username and password are from gateway .......

protected static String userName = "ranjith";

protected static String password = "ranjith";

// protected static String appPasscode = "12345";

protected static Boolean isHttpRequest = true;

// public ip

protected static String host = "69.195.215.200";

//protected static String host = "69.195.215.200";

protected static String port = "5001";

//Create the application on the server with following details. Else change the following:

protected static String appId = "AndoridApplication";

protected static String secConfig = "SSO";

protected static String domain = "default";

// protected static String appConnId = "";

protected static SDMLogger logger;

protected static SDMPreferences pref;

protected static SDMConnectivityParameters param;

protected static SDMRequestManager reqMan;

protected static ISDMODataServiceDocument serviceDoc = null;

protected static ISDMODataSchema metaDoc = null;

protected static final String dataVaultName = "SMP";

protected static ClientConnection clientConnection = null;

protected static UserManager userManager = null;

protected static AppSettings appSettings = null;

protected static void initializeRequestManager(Context context){

try{

logger = new SDMLogger();

pref = new SDMPreferences(context, logger);

pref.setStringPreference(ISDMPreferences.SDM_CONNECTIVITY_HANDLER_CLASS_NAME, SDMConstants.SDM_HTTP_HANDLER_CLASS);

pref.setBooleanPreference(ISDMPreferences.SDM_PERSISTENCE_SECUREMODE, false);

param = new SDMConnectivityParameters();

param.setUserName(Utilities.userName);

param.setUserPassword(Utilities.password);

param.enableXsrf(true);

reqMan = new SDMRequestManager(logger, pref, param, 1);

}

catch(SDMPreferencesException e){

Log.i("SMP", "Error initializing request manager");

e.printStackTrace();

}

}

}