Push notifications integration
Learn how to set up Android, FireOS, and iOS push notifications for Xamarin.
Prerequisites
To use this feature, you’ll need to integrate Braze SDK for the Xamarin platform.
Integrating push notifications
To see how namespaces change between Java and C#, check out our Xample sample app on GitHub.
To integrate push notifications for Xamarin, you’ll need to complete the steps for native Android push notifications. The following steps are only a summary. For a full walkthrough, see the native push notification guide.
Step 1: Update your project
- Add Firebase to your Android project.
- Add the Cloud Messaging library to your Android project’s
build.gradle
:1
implementation "google.firebase:firebase-messaging:+"
Step 2: Create your JSON credentials
- In Google Cloud, enable the Firebase Cloud Messaging API.
- Select Service Accounts > your project > Create Service Account, then enter a service account name, ID, and description. When you’re finished, select Create and continue.
- In the Role field, find and select Firebase Cloud Messaging API Admin from the list of roles.
- In Service Accounts, choose your project, then select Actions > Manage Keys > Add Key > Create new key. Choose JSON, then select Create.
Step 3: Upload your JSON credentials
- In Braze, select Settings > App Settings. Under your Android app’s Push Notification Settings, choose Firebase, then select Upload JSON File and upload the credentials you generated earlier. When you’re finished, select Save.
- Enable automatic FCM token registration, by going to Firebase Console. Open your project, then select Settings > Project settings. Select Cloud Messaging, then under Firebase Cloud Messaging API (V1), copy the number in the Sender ID field.
- In your Android Studio project and the following to your
braze.xml
.
1
2
<bool translatable="false" name="com_braze_firebase_cloud_messaging_registration_enabled">true</bool>
<string translatable="false" name="com_braze_firebase_cloud_messaging_sender_id">FIREBASE_SENDER_ID</string>
To prevent Braze from triggering unnecessary network requests every time you send silent push notifications, remove any automatic network requests configured in your Application
class’s onCreate()
method. For more information see, Android Developer Reference: Application.
Step 1: Complete the initial setup
See the Swift integration instructions for information about setting up your application with push and storing your credentials on our server. Refer to the iOS MAUI sample application for more details.
Step 2: Request push notifications permission
Our Xamarin SDK now supports automatic push set up. Set up push automation and permissions by adding the following code to your Braze instance configuration:
1
2
configuration.Push.Automation = new BRZConfigurationPushAutomation(true);
configuration.Push.Automation.RequestAuthorizationAtLaunch = false;
Refer to the iOS MAUI sample application for more details. For more details, see the Xamarin documentation for Enhanced User Notifications in Xamarin.iOS.