Android SDK Integration
Quick Steps Guidelines
Step 1: Select a Platform
Navigate to Netmera Panel > Developers > Netmera Onboarding and select Android.
Step 2: Create A Firebase Cloud Messaging Configuration
Create a project in the Firebase Developers Console.
Download and upload the New Private Key file to Netmera Onboarding Step 2.
Step 3: Select A Target SDK
Choose the appropriate SDK version for your application.
Step 4: Integrate and Initialize Netmera SDK
Add necessary configurations to your
build.gradle
.Initialize Netmera in the
onCreate()
of yourandroid.app.Application
.
Android 13 Push Notification Permissions
Ensure Android 13 push notification permissions are requested.
Android SDK integration completed 👏
Step 1: Select a Platform
Navigate to Netmera Panel > Developers > Netmera Onboarding and choose Android.
Click on Android > Start to proceed.
Step 2: Create a Firebase Configuration
Netmera uses Firebase Cloud Messaging (FCM) to deliver push messages to the Android devices. Therefore, you should create and configure a project on Firebase Developers Console.
At the end of the Firebase configuration, you will have a New Private Key folder of your project. That folder must be uploaded to Developers > Netmera Onboarding > Android > Step 2: Create A Firebase Configuration > FCM Service Account Key section on Netmera Panel.
Firebase Cloud Messaging Configuration
Firebase Cloud Messaging - Generate New Private Key
Upload FCM Service Account Key on Netmera Panel
Step 3: Select a Target SDK
Select the appropriate SDK for your application development framework from the following options: Native Android, Flutter, React Native, Unity. Note: The subsequent instructions on this page are specific to the Native Android SDK.
Step 4: Integrate and Initialize Android SDK
⚠️ Warning: Do not use the API key from your test panel when setting up or deploying your production app. Each panel has its own unique API key. Even if you log in with a different account, this encrypted key stays the same. Using the wrong key can result in data being sent to the incorrect environment, causing potential issues or errors in your application.
Integrate Netmera SDK
The Netmera Android SDK is conveniently available through a Maven repository. To integrate it into your project, you only need to add the following configurations to your build.gradle
file.
AndroidManifest and other resource configurations are handled automatically by the Android Gradle build tool.
Complete the following three steps below to integrate Netmera SDK.
Project Gradle - App Gradle - Setting Gradle:
If you get the following error:
“Problem occurred evaluating root project. Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle’ issue while building”
Go to setting.gradle and remove dependencyResolutionManagement block.
More info can be found here: https://stackoverflow.com/a/69197871
Initialize Netmera SDK
Add the following line of code in onCreate()
method of your class that extends **android.app.Application**
.
If you don't have such a class, you should create it and add it to your AndroidManifest file via android:name attribute of the application tag.
If your application on-premise, add this code:
configBuilder.baseUrl(baseUrl).apiKey(apiKey)
If your application is not on-premise, add this code:
configBuilder.apiKey(apiKey)
Important Note / Init Methods:
You should add init
methods in main thread. They should not be added in the background.
Init Callback (optional)
This use is optional. onSuccess
and onFailure
callbacks are added to the Init method in Android Core Update version 3.11.3. Example usage is as followed,
For further information you may visit the following page Push Callbacks.
Enable Logging (optional)
You can also enable logging with the code below. Add the following line of code in
onCreate()
method of your class that extends ** android.app.Application**
Android 13 Push Notification Permissions
Applications targeting API Level 33 and above are empowered to request push notification permissions from users as needed. This decision is in the hands of the Android operating system.
For all applications with a target level below API Level 33, when the application is running on a device with Android 13 or higher, the operating system will automatically prompt the user for these permissions during the initial creation of notification channels.
Since Netmera SDK creates notification channels after receiving the initialization response, and we advise you to call the init
method at the application level, this permission request will be triggered automatically as soon as the application is launched. However, this automatic request applies only to applications targeting Android API Level 32 and below, and it takes effect on devices running Android 13 or higher.
On devices running Android 12 and earlier, the system already behaves as if this permission has been granted by default.
Push Permission Methods in Netmera SDK
For applications targeting API 33, here's how you can use Netmera SDK when requesting push permission. At this stage, there are two important methods in Netmera SDK.
This method triggers the necessary methods to send a request for permissions to the system at any time.
Push Enable/Disable:
The users triggers the
requestNotificationPermissions()
method, the user grants permission (push enable request is sent).
After the customer receives a denial, they send the same request again (it is recommended by Google not to resend it immediately after receiving a denial), and the SDK opens the Notification settings that are specific to that application on the operating system. The user grants notification permission from the settings and returns to the application (push enable request is sent).
The users triggers the
requestNotificationPermissions()
method, the user denies permission (push disable request is sent).
After the customer receives a denial, they send the same request again (it is recommended by Google not to resend it immediately after receiving a denial), and the SDK opens the Notification settings that are specific to that application on the operating system. The user cancels (presses the back button) (push disable request is sent).
This method allows checking whether the necessary permissions for the application have been obtained. If the required permissions have been obtained from the user by the system, the method will return true, otherwise, it will return false.
Email Preferences (optional)
In version 3.9.18, a feature related to Email Preferences has been introduced. By invoking the following method, you can request email permission from users.
To clarify, if you execute the following code:
It means that email permission is revoked on your end.
Conversely, if you execute:
It signifies that permission for sending emails is granted.
Firebase Messaging Service Class (optional)
If you are incorporating Netmera's push notifications alongside another Firebase Cloud Messaging (FCM) integration, here's what you need to do:
In your Firebase Messaging Service class, consider calling Netmera's
onNetmeraPushMessageReceived
method in your ownonMessageReceived
method.When your FCM token is renewed, remember to call the
onNetmeraNewToken
method to ensure the new token is forwarded to Netmera. You can do this by callingNetmera.onNetmeraNewToken(token)
.
By following these steps, you can seamlessly integrate Netmera's push notifications into your existing FCM setup.
Important Note for Obfuscation:
If you are obfuscating your code, you don't need to add any specific rules for Netmera. Netmera's functionality remains intact even with code obfuscation.
Android SDK integration completed 👍
Android SDK integration has been successfully completed, and your devices are now ready to receive the following types of push notifications sent via the Netmera Dashboard:
Standard Push Notifications
Interactive Push Notifications
Widgets ( Enable/Disable Widget and In App Messages)
Push Notifications with Deeplinks (Android Deeplink)
Warning During App Store Submission:
During your application's store submission, you may encounter the com.google.android.gms.permission.AD_ID
alert. In this case, after proceeding with 'yes,' on the subsequent page, the 'analytics' option should also be selected. After this selection, there is no need for any additional additions to the manifest; merging the manifest is sufficient.
Last updated