Package com.yandex.metrica.push
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.StringEXTRA_ACTION_INFOstatic java.lang.StringEXTRA_PAYLOADTheStringfor extracting user definedpayload.static java.lang.StringOPEN_DEFAULT_ACTIVITY_ACTION -
Method Summary
Modifier and Type Method Description static android.app.NotificationChannelgetDefaultNotificationChannel()Method returns default notification channel.static java.lang.StringgetToken()Deprecated.static java.util.Map<java.lang.String,java.lang.String>getTokens()static voidinit(android.content.Context ctx)InitializesYandexMetricaPushwithContext.static voidinit(android.content.Context ctx, com.yandex.metrica.push.common.core.PushServiceControllerProvider... providers)static voidsetTokenUpdateListener(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_PAYLOADTheStringfor extracting user definedpayload.If you send silent push you can extract payload from silent push
BroadcastReceiverIntent.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
Activityor from your launch activity withIntent.CATEGORY_DEFAULTandIntent.ACTION_MAINif 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_ACTIONIntentaction 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)InitializesYandexMetricaPushwithContext. AppMetrica SDK should be activated before initializing ofYandexMetricaPush.- Parameters:
ctx-Contextobject. 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.YandexMetricaPushshould be initialized before.- Returns:
- push token
Stringor null if the token is not yet available - Throws:
java.lang.IllegalStateException- ifYandexMetricaPushhas 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.YandexMetricaPushshould be initialized before.- Returns:
- notification channel
NotificationChannelor null if api level less 28 - Throws:
java.lang.IllegalStateException- ifYandexMetricaPushhas not been activated yet.- See Also:
NotificationChannel
-