Register a device
Register with Amazon Pinpoint
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>