appmetrica_push_android 1.0.0 copy "appmetrica_push_android: ^1.0.0" to clipboard
appmetrica_push_android: ^1.0.0 copied to clipboard

PlatformAndroid

The AppMetrica Push SDK is a set of libraries for working with push notifications.

Flutter AppMetrica Push Android

Read this in Russian

The AppMetrica Push SDK is a set of libraries for working with push notifications. After enabling the AppMetrica Push SDK, you can create and configure push notification campaigns, then monitor statistics in the AppMetrica web interface.

SDK documentation.

SDK features #

  • Receive and display Push notifications
  • Receiving Silent Push notifications
  • Processing payload from notifications
  • image display in notifications
  • support of deeplink action when opening a notification
  • support for URL action, when you open a notification

Setup #

Add this to your project's pubspec.yaml file:

dependencies:
  firebase_core: <lastles>
  firebase_analytics: <lastles>
  appmetrica_plugin: <lastles>
  appmetrica_push_android: <lastles>

To get started with the SDK, you'll need: #

(Optional) Enable push token updating: The FCM service can withdraw the push token of the device, for example, if the user did not launch the application for a long time. AppMetrica stores push tokens on the server and can not send a push notification to a device with an obsolete token. To automatically collect current push token go to the application settings in the AppMetrica interface and enable the Update tokens with a Silent Push notification option in the Push Notifications tab.

Connecting the AppMetrica Push SDK (an example can be found in examples/example_fcm) #

In the file <project>/android/app/build.gradle put minSdkVersion 19

Using the Google Services Plugin Place the configuration file google-services.json in the module directory of the project(").

In the file " add:


buildscript {
  dependencies {
    ...
    classpath 'com.google.gms:google-services:4.3.13'
  }
}

In the file " add:


...
apply plugin: 'com.google.gms.google-services'
Without using the plugin Make changes to the application element of the AndroidManifest.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 the 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 the current_key field of the google-services.json file. You can download the file in the Firebase console.

PROJECT_ID — App ID in Firebase. You can find it in the project_id field of the google-services.json file. You can download the file in the Firebase console.

Initializing the AppMetrica Push SDK (an example can be found in examples/example_fcm) #

await Firebase.initializeApp();
await FirebaseAnalytics.instance.setAnalyticsCollectionEnabled(true);

// AppMetrica.activate must be called before AppmetricaPush.activate
await AppMetrica.activate(AppMetricaConfig('<AppMetrica API key>'));
await AppmetricaPushAndroid.instance.activate();
await AppmetricaPushAndroid.instance.requestPermission(PermissionOptions(
    alert: true,
    badge: true,
    sound: true,
  ));

Using the AppMetrica Push SDK (an example can be found in examples/example_fcm) #

// Get a PUSH service token
await AppmetricaPushAndroid.instance.getTokens();

// Streaming PUSH service tokens. Comes when the token on the device changes
// Note that this is a stream broadcast
AppmetricaPushAndroid.instance.tokenStream.listen((Map<String, String?> data) => print('token: $data'));

// Stream silent push, as the data comes payload
// Note that this is a stream broadcast
AppmetricaPushAndroid.instance.onMessage
      .listen((String data) => print('onMessage: $data'));

// Stream push, as the data comes payload
// Note that this is a stream broadcast
AppmetricaPushAndroid.instance.onMessageOpenedApp
      .listen((String data) => print('onMessageOpenedApp: $data'));

Example of work #

An example of how the SDK works is available at Example

2
likes
150
pub points
39%
popularity

Publisher

verified publishermadbrains.ru

The AppMetrica Push SDK is a set of libraries for working with push notifications.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

appmetrica_push_platform_interface, flutter

More

Packages that depend on appmetrica_push_android