YandexMetricaPush class

com.yandex.metrica.push

public final class YandexMetricaPush

Methods of the class are used for configuring the Push SDK library.

Methods

void init(@NonNull final Context ctx)

Initializes the library in the app. Method should be invoked after AppMetrica SDK initialization.

void init(@NonNull Context ctx, PushServiceControllerProvider... providers)

Initializes the library in the app with a list of push transports. Method should be invoked after AppMetrica SDK initialization.

String getToken()
Attention. Deprecated method. Use the getTokens() method instead.

Returns the push token.

Map<String, String> getTokens()

Returns a list of tokens for push providers that AppMetrica Push SDK was initialized with. The keys can take the values firebase and hms.

NotificationChannel getDefaultNotificationChannel()

Returns the push notification channel NotificationChannel, which is used by default. You can set settings for it using the methods NotificationChannel until the first push notification is received.

void setTokenUpdateListener(@NonNull TokenUpdateListener listener)

Subscribes to token updates.

void init(@NonNull final Context ctx)

Initializes the library in the app. Method should be invoked after AppMetrica SDK initialization.

void init(@NonNull Context ctx, PushServiceControllerProvider... providers)

Initializes the library in the app with a list of push transports. Method should be invoked after AppMetrica SDK initialization.

String getToken()
Attention. Deprecated method. Use the getTokens() method instead.

Returns the push token.

Map<String, String> getTokens()

Returns a list of tokens for push providers that AppMetrica Push SDK was initialized with. The keys can take the values firebase and hms.

NotificationChannel getDefaultNotificationChannel()

Returns the push notification channel NotificationChannel, which is used by default. You can set settings for it using the methods NotificationChannel until the first push notification is received.

void setTokenUpdateListener(@NonNull TokenUpdateListener listener)

Subscribes to token updates.

Fields

String OPEN_DEFAULT_ACTIVITY_ACTION

Intent action for execute the Activity by default. It can be used to detect the app start via AppMetrica push notification.

String EXTRA_PAYLOAD
An arbitrary data string that is passed in the push notification:
  • In the Additional data field when sending from the AppMetrica interface.
  • In the data field when sending using the Push API.
String OPEN_DEFAULT_ACTIVITY_ACTION

Intent action for execute the Activity by default. It can be used to detect the app start via AppMetrica push notification.

String EXTRA_PAYLOAD
An arbitrary data string that is passed in the push notification:
  • In the Additional data field when sending from the AppMetrica interface.
  • In the data field when sending using the Push API.

Method descriptions

init

void init(@NonNull final Context ctx)

Initializes the library in the app. Method should be invoked after AppMetrica SDK initialization.

Parameters:
ctx

The instance of the Context class.

ctx

The instance of the Context class.

init

void init(@NonNull Context ctx, PushServiceControllerProvider... providers)

Initializes the library in the app with a list of push transports. Method should be invoked after AppMetrica SDK initialization.

Parameters:
ctx

The instance of the Context class.

providers The instances of the FirebasePushServiceControllerProvider and HmsPushServiceControllerProvider classes.
ctx

The instance of the Context class.

providers The instances of the FirebasePushServiceControllerProvider and HmsPushServiceControllerProvider classes.
Example
YandexMetricaPush.init(
    getApplicationContext(),
    new FirebasePushServiceControllerProvider(this),
    new HmsPushServiceControllerProvider(this)
);
Copied to clipboard

getToken

String getToken()
Attention. Deprecated method. Use the getTokens() method instead.

Returns the push token.

Returns:

The push token or null, if the token is not available yet.

getTokens

Map<String, String> getTokens()

Returns a list of tokens for push providers that AppMetrica Push SDK was initialized with. The keys can take the values firebase and hms.

Returns:

List of tokens for push providers that AppMetrica Push SDK was initialized with.

getDefaultNotificationChannel

NotificationChannel getDefaultNotificationChannel()

Returns the push notification channel NotificationChannel, which is used by default. You can set settings for it using the methods NotificationChannel until the first push notification is received.

Returns:

The instance of NotificationChannel, which is used by default.

setTokenUpdateListener

void setTokenUpdateListener(@NonNull TokenUpdateListener listener)

Subscribes to token updates.

Parameters:
listener

The instance of the TokenUpdateListener class. It's called when the first token is received or updated.

listener

The instance of the TokenUpdateListener class. It's called when the first token is received or updated.

Field descriptions

OPEN_DEFAULT_ACTIVITY_ACTION

public final String OPEN_DEFAULT_ACTIVITY_ACTION = "com.yandex.metrica.push.action.OPEN"

Intent action for execute the Activity by default. It can be used to detect the app start via AppMetrica push notification.

public class LaunchActivity extends Activity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(saveInstanceState);
       Intent intent = getIntent();
       String action = intent.getAction();
       if (YandexMetricaPush.OPEN_DEFAULT_ACTIVITY_ACTION.equals(action)) {
           // Handle the app start via AppMetrica push notification.
           ...
       }
   }

}
Copied to clipboard

EXTRA_PAYLOAD

public final String EXTRA_PAYLOAD = ".extra.payload"

An arbitrary data string that is passed in the push notification:
  • In the Additional data field when sending from the AppMetrica interface.
  • In the data field when sending using the Push API.