How to retrieve username from Amazon cognito user pool in android

1.2k Views Asked by At

I am finding a way to get user name for Amazon Cognito users pool. I am using AWS Android Mobile SDK with AWS Mobile Hub. Created the user and logged in from my app. After logging in, how can i get the username with which i have logged in?

2

There are 2 best solutions below

0
Bommas On

You can use the com.amazonaws.mobile.client.AWSMobileClient to integrate with cognito user pools. AWSMobileClient has the getUsername method that will return the signed-in user's username.

See the aws-sdk-android api reference ( available at https://aws-amplify.github.io/aws-sdk-android/docs/reference/) for more information

1
Baraseel On

You can get user name by using this method

String getCurrentValue(){
    AuthUser authUser=Amplify.Auth.getCurrentUser();
    Log.e("getCurrentUser", authUser.toString());
    Log.e("getCurrentUser", authUser.getUserId());
    Log.e("getCurrentUser", authUser.getUsername());
    return authUser.getUsername();
}