Class YandexMetricaPush

java.lang.Object
com.yandex.metrica.push.YandexMetricaPush

public final class YandexMetricaPush
extends java.lang.Object
Main entry point for AppMetrica Push SDK.
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.String EXTRA_ACTION_INFO  
    static java.lang.String EXTRA_PAYLOAD
    The String for extracting user defined payload.
    static java.lang.String OPEN_DEFAULT_ACTIVITY_ACTION
    Intent action for performing opening default launcher activity.
  • Method Summary

    Modifier and Type Method Description
    static android.app.NotificationChannel getDefaultNotificationChannel()
    Method returns default notification channel.
    static java.lang.String getToken()
    Deprecated.
    static java.util.Map<java.lang.String,​java.lang.String> getTokens()  
    static void init​(android.content.Context ctx)
    Initializes YandexMetricaPush with Context.
    static void init​(android.content.Context ctx, com.yandex.metrica.push.common.core.PushServiceControllerProvider... providers)  
    static void setTokenUpdateListener​(com.yandex.metrica.push.TokenUpdateListener listener)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • EXTRA_PAYLOAD

      public static final java.lang.String EXTRA_PAYLOAD
      The String for extracting user defined payload.

      If you send silent push you can extract payload from silent push BroadcastReceiver Intent.

      EXAMPLE

      import com.yandex.metrica.push.YandexMetricaPush;
      
        public class SilentPushReceiver extends BroadcastReceiver {
      
            @Override
            public void onReceive(Context context, Intent intent) {
                //extract you payload
                String payload = intent.getStringExtra(YandexMetricaPush.PAYLOAD);
                //process your payload here
            }
        }
       }
       

      If you send general push you can extract payload from your deeplink Activity or from your launch activity with Intent.CATEGORY_DEFAULT and Intent.ACTION_MAIN if push message notification action url is not defined.

      EXAMPLE

      
            import com.yandex.metrica.push.YandexMetricaPush;
      
            public class DeeplinkOrLaunchActivity extends Activity {
      
                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(saveInstanceState);
                    handlePayload(getIntent());
                }
      
                @Override
                protected void onNewIntent(Intent intent) {
                    super.onNewIntent(intent);
                    handlePayload(intent);
                }
      
                private void handlePayload(Intent intent) {
                    //extract you payload
                    String payload = intent.getStringExtra(YandexMetricaPush.PAYLOAD);
                    //process your payload here
                }
            }
       
      See Also:
      BroadcastReceiver, Intent, Intent.CATEGORY_DEFAULT, Intent.ACTION_MAIN, Activity, Activity.onCreate(android.os.Bundle), Activity.onNewIntent(android.content.Intent), Constant Field Values
    • EXTRA_ACTION_INFO

      public static final java.lang.String EXTRA_ACTION_INFO
      See Also:
      Constant Field Values
    • OPEN_DEFAULT_ACTIVITY_ACTION

      public static final java.lang.String OPEN_DEFAULT_ACTIVITY_ACTION

      Intent action for performing opening default launcher activity. You can use it for detecting application launch on AppMetrica Push message notification action.

      EXAMPLE

      
            import com.yandex.metrica.push.YandexMetricaPush;
      
            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)) {
                        //Process opening application via AppMetrica Push message notification action
                    }
                }
      
            }
      
       
      See Also:
      Constant Field Values
  • Method Details

    • init

      public static void init​(@NonNull android.content.Context ctx)
      Initializes YandexMetricaPush with Context. AppMetrica SDK should be activated before initializing of YandexMetricaPush.
      Parameters:
      ctx - Context object. Any application context.
      Throws:
      java.lang.IllegalStateException - if AppMetrica SDK has not been activated yet.
      See Also:
      Context, AppMetrica SDK documentation
    • init

      public static void init​(@NonNull android.content.Context ctx, com.yandex.metrica.push.common.core.PushServiceControllerProvider... providers)
    • getToken

      @Nullable @Deprecated public static java.lang.String getToken()
      Deprecated.
      Method returns used push token. YandexMetricaPush should be initialized before.
      Returns:
      push token String or null if the token is not yet available
      Throws:
      java.lang.IllegalStateException - if YandexMetricaPush has not been activated yet.
      See Also:
      YandexMetricaPush
    • getTokens

      @Nullable public static java.util.Map<java.lang.String,​java.lang.String> getTokens()
    • setTokenUpdateListener

      public static void setTokenUpdateListener​(@NonNull com.yandex.metrica.push.TokenUpdateListener listener)
    • getDefaultNotificationChannel

      @Nullable public static android.app.NotificationChannel getDefaultNotificationChannel()
      Method returns default notification channel. YandexMetricaPush should be initialized before.
      Returns:
      notification channel NotificationChannel or null if api level less 28
      Throws:
      java.lang.IllegalStateException - if YandexMetricaPush has not been activated yet.
      See Also:
      NotificationChannel