Skip to content

Instantly share code, notes, and snippets.

@alizahid
Last active March 23, 2017 14:31
Show Gist options
  • Select an option

  • Save alizahid/05c978e13e24385e2261 to your computer and use it in GitHub Desktop.

Select an option

Save alizahid/05c978e13e24385e2261 to your computer and use it in GitHub Desktop.
SMP 3.0 SMP07 Android registration and logout
public class LoginActivity extends Activity implements LogonCoreListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadingSpinner = new LoadingSpinner(this);
loadingSpinner.show();
// get instance
logonCore = LogonCore.getInstance();
// set listener for LogonCore
logonCore.setLogonCoreListener(this);
// boot up
logonCore.init(this, "com.example.mysmpapp");
// check if store is open and available
// open and unlock if not
try {
if (!logonCore.isStoreAvailable()) {
logonCore.createStore(null, false);
}
logonCore.unlockStore(null);
} catch (LogonCoreException e) {
e.printStackTrace();
}
// check if user is ALREADY registered or not
if (logonCore.isRegistered()) {
// send user to main activity
Intent intent = new Intent(this, DashboardActivity.class);
startActivity(intent);
// finish this activity
finish();
} else {
// show login form
setContentView(R.layout.activity_login);
}
}
// call this method from your layout
// using android:onClick="login" on a button
// or however else you want to
public void login(View view) {
// replace credentials with the real deal
String username = "test";
String password = "123";
// create LogonCoreContext
// this is used for registration
LogonCoreContext context = logonCore.getLogonContext();
// set configuration
try {
context.setHost("myserver.com");
context.setPort(80);
context.setHttps(false);
// context.setFarmId("MYFARM.SUPFarm");
context.setSecurtityConfig("default");
// context.setResourcePath("ias_relay_server/client/rs_client.dll");
context.setDomain("default");
// MOST important part!
context.setChannel(LogonCore.Channel.REST);
context.setBackendUser(username);
context.setBackendPassword(password);
// call registration
logonCore.register(context);
} catch (LogonCoreException e) {
e.printStackTrace();
}
}
// LogonCoreListener methods
@Override
public void registrationFinished(boolean success, String message, int errorCode, DataVault.DVPasswordPolicy dvPasswordPolicy) {
if (success) {
try {
// if successful, persist registration
// DO NOT follow the manual storage of APPCID as shown in SMP docs
logonCore.persistRegistration();
// send user to main activity
Intent intent = new Intent(this, DashboardActivity.class);
startActivity(intent);
// finish this activity
finish();
} catch (LogonCoreException e) {
e.printStackTrace();
}
} else {
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT);
}
}
@Override
public void deregistrationFinished(boolean success) {
}
@Override
public void backendPasswordChanged(boolean success) {
}
@Override
public void applicationSettingsUpdated() {
}
@Override
public void traceUploaded() {
}
}
private void logout() {
// call deregister
LogonCore.getInstance().deregister();
try {
// close online, if you opened it
onlineStore.close();
// clear technical cache for offline store
// so there's nothing in the cache for the next user
// prevents confusion if you're using the requestCacheResponse method
onlineStore.resetCache();
// close offline store
// but not clear the data in it
offlineStore.closeStore();
} catch (ODataException e) {
e.printStackTrace();
}
// back to login activity
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
// finish this!
finish();
}
Copy link

ghost commented Jun 24, 2015

Hi Ali,

I was wondering if you could help me with an issue I'm having and I'll like to know how are you handle it, since on internet I could not find any information of this. The problem is to handle the connection errors of the device to the Managment Cockpit.

I would really appretiate any light that you can give me on this.

Thanks in advance.

Best regards,
Ana

@timothy2005
Copy link

Hi Ali, your code are really helpful, thank you very much.
Is it possible for you to share code of DashboardActivity.class as well?
I really want to learn How to get the business data from backend system.
Now I have successfully registered to SMP through my app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment