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

Register a device

Register with Amazon Pinpoint

You do not need to add these APIs to your app if you want to use Amplify with Amazon Pinpoint. You should use these APIs if you are interested in supporting multiple push providers.

You can use the Amplify.Notifications.Push.registerDevice() method to register the device with Pinpoint.

class MyAppService : FirebaseMessagingService() {
// Called when a new token for the default Firebase project is generated
@Override
public void onNewToken(String token) {
super.onNewToken(token)
// Register device with Pinpoint
Amplify.Notifications.Push.registerDevice(token,
() -> Log.i("MyAmplifyApp", "Successfully registered device"),
error -> Log.e("MyAmplifyApp", "Error registering device", error)
);
}
}
class MyAppService : FirebaseMessagingService() {
// Called when a new token for the default Firebase project is generated
override fun onNewToken(token: String) {
super.onNewToken(token)
// Register device with Pinpoint
Amplify.Notifications.Push.registerDevice(token,
{ Log.i("MyAmplifyApp", "Successfully registered device") },
{ Log.e("MyAmplifyApp", "Error registering device", error) }
)
}
}
class MyAppService : FirebaseMessagingService() {
// Called when a new token for the default Firebase project is generated
override fun onNewToken(token: String) {
super.onNewToken(token)
try {
// Register device with Pinpoint
Amplify.Notifications.Push.registerDevice(token)
Log.i("MyAmplifyApp", "Successfully registered device")
} catch (error: PushNotificationsException) {
Log.e("MyAmplifyApp", "Error registering device", error)
}
}
}
class MyAppService : FirebaseMessagingService() {
// Called when a new token for the default Firebase project is generated
@Override
public void onNewToken(String token) {
super.onNewToken(token)
// Register device with Pinpoint
RxAmplify.Notifications.Push.registerDevice(token).subscribe(
() -> Log.i("MyAmplifyApp", "Successfully registered device"),
error -> Log.e("MyAmplifyApp", "Error registering device", error)
);
}
}

You must also add the custom service extension to AndroidManifest.xml in the application tag:

<service android:name=".MyAppService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>