0
votes

I have created a sample Android app using AWS mobile hub. Followed the Developer guide (https://docs.aws.amazon.com/aws-mobile/latest/developerguide/getting-started.html) and Added User Sign-in to Mobile App with Amazon Cognito.

Created a user and am successful in logging in. After logging in, I want to find the username with which i have logged in. These details will be sent to database to have a record on how many users have logged in.

Can any one suggest me how to fetch the username

1
Hi, you could use getUserPool() method's getCurrentUser() and then call getDetails() which has the username and all other information. You can also explicitly store the username information if its not available, and then also store in database of your choice. - Rohan Dubal
Hi Rohan, Thanks for the info. I am unable to find the appropriate instance to call getUserPool() and its subsequent methods. Can you please share more details on how exactly this call should be made? I am not creating any user pool programmatically. I have created user pool using AWS Cognito Mobile Hub console and in app i have logged in with the created credentials. Now from the Android app, i want to fetch the username. Is this possible? - Mohan

1 Answers

0
votes

Issue is resolved. I have used below code to get the username:
CognitoUserPool userpool = new CognitoUserPool(AuthenticatorActivity.this, new AWSConfiguration(AuthenticatorActivity.this)); String str = userpool.getCurrentUser().getUserId();