How to maintain one time login in android screenlet app ?

Amit Sinha, modified 9 Years ago. Junior Member Posts: 43 Join Date: 12/31/14 Recent Posts
Hi Everyone,

I have created an android liferay screenlet app. The app is working fine but there is an annoying issue while using.
If a user install that app, a token for his mobile number is added in pushnotifications device section.
Now everytime this user gets notification, to check his notification he has to perform authentication
Also user has to authenticate whenever he opens his app first time by clicking its icon on mobile.

Is there any way that user has to authenticate himself only once. After that whenever his gets notification he can see it without login. Similarly he shouldn't login to open this app.
Does user name, and token for his mobile should be saved along with his login critential in database.

Waiting for guidance.
Thanks and Regards,
Amit.
thumbnail
Javier Gamarra, modified 9 Years ago. Expert Posts: 348 Join Date: 2/12/15 Recent Posts
I think you are looking for something like this: https://www.youtube.com/watch?v=kEZEahTzuck

There has been some API changes but the basics are the same, to store the credentials and login before showing a screen to the user.
Amit Sinha, modified 9 Years ago. Junior Member Posts: 43 Join Date: 12/31/14 Recent Posts
Thanks Javier,
with a little modifications in code, the code worked.
User do not have to re login every time.

some modification required were as below :

import com.liferay.mobile.screens.context.storage.CredentialsStorageBuilder;
instead of
// import com.liferay.mobile.screens.context.storage.CredentialsStoreBuilder;

SessionContext.loadStoredCredentials(CredentialsStorageBuilder.StorageType.SHARED_PREFERENCES);
instead of
// SessionContext.loadSessionFromStore(CredentialsStoreBuilder.StorageType.SHARED_PREFERENCES);

if (SessionContext.isLoggedIn()){}
instead of
// if (SessionContext.hasSession()) {}

and in activity xml file

app:credentialsStorage="shared_preferences"
instead of
<!-- app:credentialsStore="shared_preferences" -->

Once Again Thanks Javier.

Amit.
thumbnail
Javier Gamarra, modified 9 Years ago. Expert Posts: 348 Join Date: 2/12/15 Recent Posts
Thanks to you emoticon