problem while getting username.

0 votes

Hi Shephertz,

 

I am trying to get username of person who have logged in. but unable t get it. please check the following code, for this i have followed your SampleAPITest example.

Dashboard.java

 

private TextView tv;

private AsyncApp42ServiceApi asyncService;

private String userName;

 

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dashboard);
        asyncService = AsyncApp42ServiceApi.instance();
        asyncService.getUser(userName, this);
 
        tv = (TextView) findViewById(R.id.username);
 
@Override
public void onGetUserSuccess(User response) {
String userName = response.getUserName();
tv.setText(userName);
 
 
}
 
@Override
public void onGetUserFailed(App42Exception exception) {
// TODO Auto-generated method stub
 
}
 
public String getUserName() {
return userName;
}
 
public void setUserName(String userName) {
this.userName = userName;
}
 

}

 

 

AsyncApp42ServiceApi.java

 

public class AsyncApp42ServiceApi {
private UserService userService;
private StorageService storageService;
private UploadService uploadService;
private ScoreBoardService scoreBoardService;
private static AsyncApp42ServiceApi mInstance = null;
 
private AsyncApp42ServiceApi() {
ServiceAPI sp = new ServiceAPI(Constants.App42ApiKey,
Constants.App42ApiSecret);
this.userService = sp.buildUserService();
 
}
 
 
public static AsyncApp42ServiceApi instance() {
 
if (mInstance == null) {
mInstance = new AsyncApp42ServiceApi();
}
 
return mInstance;
}
 
public void getUser(final String name, final App42UserServiceListener callBack) {
final Handler callerThreadHandler = new Handler();
new Thread() {
@Override
public void run() {
try {
final User response = userService.getUser(name);
callerThreadHandler.post(new Runnable() {
@Override
public void run() {
callBack.onGetUserSuccess(response);
}
});
} catch (final App42Exception ex) {
callerThreadHandler.post(new Runnable() {
@Override
public void run() {
if (callBack != null) {
callBack.onGetUserFailed(ex);
}
}
});
}
}
}.start();
}
 
 
public static interface App42UserServiceListener {
 
 
public void onGetUserSuccess(User response);
 
public void onGetUserFailed(App42Exception exception);
 
 
 
}

}

asked Nov 22, 2014 in App42 Cloud API-BaaS by shivdataservices (30 points)

1 Answer

0 votes
 
Best answer

Hi,

According to code snippet you have shared, you havn't intialize the userName variable, which user you want to retrieve form App42. So Please see logcat as well or you can also follow these steps mentioned in the Sample application:

  1. First create user on App42 that you want to retrieve again.
  2. Than paas that userName with the function getUser to retrieve user details.

In case of further query, please feel free to write us.

Thanks

Vishnu

answered Nov 22, 2014 by Vishnu Garg (674 points)
selected Nov 30, 2014 by shivdataservices
Hi Vishnu, Thanks for your response. GettingUser problem has been solved. but, i want to know that, is it possible to authenticate user on dashboard?

 After following tic tac toe sample, when we open this app OR close from recent app tray and open again, always it shows login screen, which is annoying. i have tried sharedpreference for Session Management but did not worked for me.

I dont want to show LoginActivity everytime when user open app, but only when user installed app first time or logged out from app. I am posting my sample project here, please look into it.

https://www.dropbox.com/s/e73votqz9e4f36f/GetUserInfo.rar?dl=0
Hey , You can remove Login screen as per your requirement is concern and save it accordingly in shared preferences, If you look to TicTacToe sample, in Fb authentication I didn't create user and save it on preferences because facebook Id is unique.
    So you can skip the login screen as per your requirements and create a unique user with App42 and accordingly set its profile as well, and save profile in shared preferences and skip the login screen
Vishnu, Thanks for your comment. you are right bro, but actually i am trying to skip login screen from last 4 days, but not able to achieve that. I have tried many of samples available on google search. Please can u look at above sample project and modify according it. Plz help.

Thanks.
Hey, I have updated your sample a little bit, in such a way you can skip the login screen when user came on next time if he is already registered with App42 and able to connect with AppWarp as well.
Here is Drop-box link :
https://www.dropbox.com/s/9gvxoz0sqpqruok/GetUserInfo.zip?dl=0

Thanks
Vishnu
Thanks bro, u r genius. Thats the thing i was looking for, this wasted my 4 days, but you did it in just 4 easy steps.

Thanks
Shiv
Your always welcome to ShepHertz.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...