In your app’s build.gradle file, set the SDK version parameters to the versions listed in this table.
Parameter
Version
compileSdk or compileSdkVersion
35
minSdkVersion
23
Update Kotlin Version
Ensure the org.jetbrains.kotlin.android or org.jetbrains.kotlin:kotlin-gradle-plugin plugin is version 1.9.10 or later.
Depending on your Flutter implementation, the location for specifying the Kotlin version can differ. You can specify the Kotlin version in either android/build.gradle or android/settings.gradle.
Important
Provide Firebase Cloud Messaging Credentials
To enable push support for the Android platform, provide your Firebase Cloud Messaging (FCM) credentials by including the google-services.json file in your config.xml file.
Download the google-services.json file from your application’s Firebase console and place it in your project’s android/app directory
To include the Google Services plugin, add this code to your android/settings.gradle file.
If pluginManagement isn’t present in your settings.gradle, add this dependency in android/build.gradle under the buildscript section. If the Gradle file doesn’t have a buildscript section, add it.
Note
To apply the plugin, add this code to your android/app/build.gradle file.
This step can vary depending on your implementation.
Note
android/app/build.gradle
1plugins {2 id "com.google.gms.google-services"3}
If the plugins section doesn’t exist in your android/app/build.gradle file, add this code to the end of the file.
android/app/build.gradle
1// Add the google services plugin to your build.gradle file2apply plugin: 'com.google.gms.google-services'
Update MainApplication.kt
If MainApplication.kt isn’t present in your app, create it by extending the FlutterApplication class. Additionally, update AndroidManifest.xml.
Note
AndroidManifest.xml
1// add ".MainApplication" entry in main/AndroidManifest.xml23<application android:name=".MainApplication" ...>
Update MainApplication.kt in your app.
MainApplication.kt
1//MainApplication.kt23//YOUR_package45//rest of imports...6import android.util.Log7import com.salesforce.marketingcloud.MarketingCloudConfig8import com.salesforce.marketingcloud.notifications.NotificationCustomizationOptions9import com.salesforce.marketingcloud.sfmcsdk.InitializationStatus10import com.salesforce.marketingcloud.sfmcsdk.SFMCSdk11import com.salesforce.marketingcloud.sfmcsdk.SFMCSdkModuleConfig12import io.flutter.app.FlutterApplication1314class MainApplication : FlutterApplication(){1516 //Update onCreate17 override fun onCreate(){18 super.onCreate()1920 SFMCSdk.configure(21 applicationContext,22 SFMCSdkModuleConfig.build{23 pushModuleConfig =24 MarketingCloudConfig.builder()25 .apply{26 //Update these details based on your MC config27 setApplicationId("{MC_APP_ID}")28 setAccessToken("{MC_ACCESS_TOKEN}")29 setMarketingCloudServerUrl("{MC_APP_SERVER_URL}")30 setSenderId("{FCM_SENDER_ID_FOR_MC_APP}")31 setNotificationCustomizationOptions(32 NotificationCustomizationOptions.create(33 R.mipmap.ic_launcher34)35)36}37 .build(applicationContext)38}39){ initStatus ->40 when(initStatus.status){41 InitializationStatus.SUCCESS -> Log.d("SFMC", "SFMC SDK Initialization Successful")42 InitializationStatus.FAILURE -> Log.d("SFMC", "SFMC SDK Initialization Failed")43 else -> Log.d("SFMC", "SFMC SDK Initialization Status: Unknown")44}45}4647 //rest of onCreate...48}4950 //rest of MainApplication...51}
Update AndroidManifest.xml to declare the notification permission.
AndroidManifest.xml
1//AndroidManifest.xml2<manifest ...>3 //Add this line to declare the notification permission.4 <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>5 <application ...>6 ...7 </application>8</manifest>
Handle URLs
The SDK doesn’t automatically present URLs from these sources.
CloudPages URLs from push notifications
OpenDirect URLs from push notifications
Action URLs from in-app messages
To handle URLs from push notifications, follow these steps.
Navigate to MainApplication.kt and update setNotificationCustomizationOptions to include the code in this example.
Open MainApplication.kt in an editor.
In the setNotificationCustomizationOptions section, add these import statements.
1//MainApplication.kt23private fun provideIntentFlags(): Int{4 return if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){5 PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE6}else{7 PendingIntent.FLAG_UPDATE_CURRENT8}9}1011private fun getPendingIntent(12 context: Context,13 notificationMessage: NotificationMessage14): PendingIntent{15 val intent = if(notificationMessage.url.isNullOrEmpty()){16 context.packageManager.getLaunchIntentForPackage(context.packageName)17}else{18 Intent(Intent.ACTION_VIEW, Uri.parse(notificationMessage.url))19}20 return PendingIntent.getActivity(context, Random().nextInt(), intent, provideIntentFlags())21}
Handle URLs from In-App messages
To handle URLs from in-app messages, set the setUrlHandler in MarketingCloudConfig as shown in this example.
MainApplication.kt
1//MainApplication.kt23// Add import statement for UrlHandler4import com.salesforce.marketingcloud.UrlHandler56// Tell the SDK how to handle button clicks in an IAM7setUrlHandler(UrlHandler{ context, url, _ ->8 PendingIntent.getActivity(9 context,10 Random().nextInt(),11 Intent(Intent.ACTION_VIEW, Uri.parse(url)),12 PendingIntent.FLAG_UPDATE_CURRENT13)14})
If you encounter errors related to Java sealed classes or dexing, add the r8 dependency to your app. For more information about this error, see Google’s IssueTracker.
To add the r8 dependency, update your app’s settings.gradle file.
If you don’t have pluginManagement in your settings.gradle file, update the buildscript.dependencies section of the android/build.gradle file.