Installation and initialization
To integrate AppMetrica Push SDK into Flutter, use the AppMetrica Push SDK for Flutter plugin:
-
Install the AppMetrica Push SDK plugin in your project. From the root of the project, run the command:
flutter pub add appmetrica_push_plugin
After adding the plugin, you'll see a line with the following dependency in the
pubspec.yaml
file:dependencies: appmetrica_push_plugin: ^2.0.0
-
Add
appmetrica_plugin
andappmetrica_push_plugin
import:import 'package:appmetrica_plugin/appmetrica_plugin.dart'; import 'package:appmetrica_push_plugin/appmetrica_push_plugin.dart';
-
Initialize the AppMetrica SDK library using
AppMetrica.activate
and your API key:AppMetrica.activate(AppMetricaConfig("insert_your_api_key_here"));
-
Initialize the AppMetrica Push SDK using
AppMetricaPush.activate
and your API key:AppMetricaPush.activate();
-
To complete the integration of sending push notifications, use the documentation for each native platform:
AndroidiOS1. Set up the app for using Firebase. Get and add to AppMetrica a server key for using Firebase Cloud Messaging:
2. Connect Firebase transport by adding the following dependencies to the
android/app/build.gradle
file:dependencies { implementation "com.google.firebase:firebase-messaging: 22.0.0" implementation "com.google.android.gms:play-services-base: 17.5.0" }
3. Initialize Firebase transport using one of the following methods:
Using Google Services Plugin
1. Download the configuration file
google-services.json
and put it in the project module's directory (such asapp
).2. For the file to work correctly, enable the Google Services plugin in the project by adding the following lines to the Gradle file:
project
-
build.gradle.kts
buildscript { dependencies { classpath("com.google.gms:google-services:4.4.0") } }
-
build.gradle
buildscript { dependencies { classpath "com.google.gms:google-services:4.4.0" } }
application (module)
-
app/build.gradle.kts
apply(plugin = "com.google.gms.google-services")
-
app/build.gradle
apply plugin: "com.google.gms.google-services"
Without using the plugin
Make changes in the
application
element in theAndroidManifest.xml
file:<meta-data android:name="ymp_firebase_default_app_id" android:value="APP_ID"/> <meta-data android:name="ymp_gcm_default_sender_id" android:value="number:SENDER_ID"/> <meta-data android:name="ymp_firebase_default_api_key" android:value="API_KEY"/> <meta-data android:name="ymp_firebase_default_project_id" android:value="PROJECT_ID"/>
APP_ID
— ID of the app in Firebase. You can find it in the Firebase console: go to the Project settings. In the Your application section copy the value of the application ID field.SENDER_ID
— The unique ID of sender in Firebase. You can find it in the Firebase console: go to Project settings → Cloud Messaging and copy the value of the Sender ID field.API_KEY
— App key in Firebase. You can find it in thecurrent_key
field of thegoogle-services.json
file. You can download the file in the Firebase console.PROJECT_ID
— App ID in Firebase. You can find it in theproject_id
field of thegoogle-services.json
file. You can download the file in the Firebase console.Using with other Firebase projects
Make changes in the
application
element in theAndroidManifest.xml
file:<meta-data android:name="ymp_firebase_app_id" android:value="APP_ID"/> <meta-data android:name="ymp_gcm_sender_id" android:value="number:SENDER_ID"/> <meta-data android:name="ymp_firebase_api_key" android:value="API_KEY"/> <meta-data android:name="ymp_firebase_project_id" android:value="PROJECT_ID"/>
APP_ID
— ID of the app in Firebase. You can find it in the Firebase console: go to the Project settings. In the Your application section copy the value of the application ID field.SENDER_ID
— The unique ID of sender in Firebase. You can find it in the Firebase console: go to Project settings → Cloud Messaging and copy the value of the Sender ID field.API_KEY
— App key in Firebase. You can find it in thecurrent_key
field of thegoogle-services.json
file. You can download the file in the Firebase console.PROJECT_ID
— App ID in Firebase. You can find it in theproject_id
field of thegoogle-services.json
file. You can download the file in the Firebase console.Alert
You should initialize default Firebase project.
4. If needed, configure silent push notifications or enable push tokens update.
1. Add the SSL certificate to AppMetrica according to the instructions.
2. Add Capability Push Notifications to your XCode project.
3. If needed, enable push tokens update or configure uploading of attached files.
4. Set up statistics collection.
-
If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.