Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Feb 21, 2024

Identify user to Amazon Pinpoint

This call identifies the current user (which could be unauthenticated or authenticated) to Amazon Pinpoint. The user ID can be any string which identifies the user in the context of your application.

Get the user ID from Amplify Auth

If the user is signed in through Amplify.Auth.signIn, then you can retrieve the current user's ID as shown below:

Amplify.Auth.getCurrentUser(
authUser -> String userId = authUser.getUserId(),
error -> Log.e("MyAmplifyApp", "Error getting current user", error)
);
Amplify.Auth.getCurrentUser(
{ authUser -> val userId = authUser.userId },
{ Log.e("MyAmplifyApp", "Error getting current user", it) }
)
try {
val userId = Amplify.Auth.getCurrentUser().userId
} catch (error: PushNotificationsException) {
Log.e("MyAmplifyApp", "Error getting current user", error)
}
RxAmplify.Auth.getCurrentUser().subscribe(
authUser -> String userId = authUser.getUserId(),
error -> Log.e("MyAmplifyApp", "Error getting current user", error)
);

Identify the user to Amazon Pinpoint

Once you have a string that identifies the current user (either from the Auth category as shown above or through your own application logic), you can identify the user to Amazon Pinpoint with the following:

Amplify.Notifications.Push.identifyUser(user,
() -> Log.i("MyAmplifyApp", "Identified user successfully"),
error -> Log.e("MyAmplifyApp", "Error identifying user", error)
);
Amplify.Notifications.Push.identifyUser(user,
{ Log.i("MyAmplifyApp", "Identified user successfully") },
{ Log.e("MyAmplifyApp", "Error identifying user", error) }
)
try {
Amplify.Notifications.Push.identifyUser(user)
Log.i("MyAmplifyApp", "Identified user successfully")
} catch (error: PushNotificationsException) {
Log.e("MyAmplifyApp", "Error identifying user", error)
}
RxAmplify.Notifications.Push.identifyuser(user).subscribe(
() -> Log.i("MyAmplifyApp", "Identified user successfully"),
error -> Log.e("MyAmplifyApp", "Error identifyUser user", error)
);

Alternatively, you can provide additional information about the user by passing a user profile:

AWSNotificationsUserProfile profile = AWSNotificationsUserProfile.builder()
.name("Name")
.build()
Amplify.Analytics.identifyUser(
user,
profile,
() -> Log.i("MyAmplifyApp", "Identified user successfully"),
error -> Log.e("MyAmplifyApp", "Error identifying user", error)
);
val profile = AWSNotificationsUserProfile.builder()
.name("Name")
.build()
Amplify.Analytics.identifyUser(
user,
profile,
{ Log.i("MyAmplifyApp", "Identified user successfully") },
{ Log.e("MyAmplifyApp", "Error identifying user", error) }
)
val profile = AWSNotificationsUserProfile.builder()
.name("Name")
.build()
try {
Amplify.Notifications.Push.identifyUser(user, profile)
Log.i("MyAmplifyApp", "Identified user successfully")
} catch (error: PushNotificationsException) {
Log.e("MyAmplifyApp", "Error identifying user", error)
}
AWSNotificationsUserProfile profile = AWSNotificationsUserProfile.builder()
.name("Name")
.build()
RxAmplify.Notifications.Push.identifyuser(user, profile).subscribe(
() -> Log.i("MyAmplifyApp", "Identified user successfully"),
error -> Log.e("MyAmplifyApp", "Error identifyUser user", error)
);