Android SDK Integration
Last updated
Last updated
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 and 5: Integrate and Initialize Netmera SDK
Add necessary configurations to your build.gradle
.
Initialize Netmera in the onCreate()
of your android.app.Application
.
Android 13 Push Notification Permissions
Ensure Android 13 push notification permissions are requested.
Android SDK integration completed 👏
Please find the Onboarding Checklist for iOS and Android below. Follow the titles in the checklist to ensure you have completed each essential step in your onboarding process with Netmera.
Navigate to Netmera Panel > Developers > Netmera Onboarding and choose Android.
Click on Android > Start to proceed.
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.
Project > app
directory.About the Admin SDK Configuration Snippet:
There are 4 different options available on this screen. The choice of which option to select is not important as the code just indicates the language in which it will be generated. We add this code to Netmera, and there is no action required from customers to add or choose anything. Users can simply download the file by clicking the 'Generate New Private Key' button without making any selections on this page.
Select the SDK for your application development framework as Native Android SDK.
Warning About API Key: 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.
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 below to integrate Netmera SDK. The steps vary according to your use of Gradle 8 or below.
Note: Check your libs.versions.toml
file:
This file is usually located within the gradle
folder in the root directory of your project.
Review how the relevant plugin is defined.
Note: Check your libs.versions.toml
file:
This file is usually located within the gradle
folder in the root directory of your project.
Review how the relevant plugin is defined.
In this step, only copy the url specified below and add it to maven.
Add Initialization Code in onCreate()
Method:
To ensure proper initialization, add the code below within the onCreate()
method of your class that extends android.app.Application
If your project does not currently have a class that extends Application:
Create an Application Class
If your project does not currently have a class that extends Application
, create one.
Update AndroidManifest File:
Add the newly created or existing Application
class to your AndroidManifest.xml
file using the android:name
attribute within the <application>
tag. Then, add initialization code below.
Implementation Note: Configuring baseUrl for On-Premise Applications
For On-Premise Applications: If your application is on-premise, include the following code to configure the base URL and API key:
For Non-On-Premise Applications: If your application is not on-premise, only the API key needs to be configured:
Warning: Init Method Must Be Added in the Main Thread
Ensure that init
methods are added in the main thread. Adding them in the background may lead to unexpected behavior and potential issues.
Adding callbacks to the initialization method is optional. In Android Core Update version 3.11.3, onSuccess
and onFailure
callbacks were introduced for the Init method. Below is an example of how to implement this: For more detailed information, you can visit the following page >Push Callbacks
You can also enable logging by adding the following code in the onCreate()
method of your class that extends android.app.Application.
This will enable logging, allowing you to monitor and debug the SDK's operations more effectively.
Set .logging (false)
while on prod:
When preparing your app for release to the store, ensure that .logging
is disabled (set to false
) in the production environment.
For apps targeting API Level 33 (Android 13) and above, you can now request push notification permissions directly from users. This is controlled by the Android operating system.
For Apps Targeting API Level 33 and Above: You need to explicitly request push notification permissions from users. This is done through your app's code.
For Apps Targeting API Level 32 and Below: On devices running Android 13 or higher, the system will automatically prompt users for push notification permissions when the app creates notification channels. This happens when you initialize the Netmera SDK at the application level.
On Android 12 and Earlier: The system treats push notification permissions as granted by default, so no additional action is needed.
This means that for most apps, especially those targeting older API levels, the permission request will be handled automatically when the app starts.
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 must be added in the main activity below super.Oncreate(savedInstanceState)
. It 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.
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.
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 own onMessageReceived
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 calling Netmera.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.
Netmera provides the following push callbacks:
Push Register, Push Receive, Push Open, Push Dismiss, Push Button Click
If you would like to use push callbacks in Netmera, please visit our documentation Push Callbacks.
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)
Please find the Onboarding Checklist for iOS and Android below. Follow the titles in the checklist to ensure you have completed each essential step in your onboarding process with Netmera.
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.