Package com.netmera

Class Netmera


  • public class Netmera
    extends java.lang.Object
    Netmera is the main class to be used for configuring the SDK and interacting with Netmera servers.
    • Constructor Detail

      • Netmera

        public Netmera()
    • Method Detail

      • init

        public static void init​(NetmeraConfiguration netmeraConfiguration)
        Initialize the Netmera instance.

        Netmera does not start operating, it even does not exist, unless this method is called. Any Netmera method called before this method is simply ignored.

        In order for Netmera to operate correctly, this method must definitely be called in the Application.onCreate() method.

        Parameters:
        netmeraConfiguration - NetmeraConfiguration encapsulates all the necessary information for initialization of Netmera instance.
      • init

        public static void init​(NetmeraConfiguration netmeraConfiguration,
                                NMInitSessionListener listener)
      • kill

        public static void kill()
      • setBaseUrl

        public static void setBaseUrl​(java.lang.String url)
        Changes base API URL to given URL string.

        The only use case for this method is when a custom Netmera domain is defined to your application.

        Parameters:
        url - Custom domain string.
      • skipAppConfigAndSetBaseUrl

        public static void skipAppConfigAndSetBaseUrl​(java.lang.String url)
      • setApiKey

        public static void setApiKey​(java.lang.String apiKey)
        Set given Netmera SDK API key.

        Calling this method with a valid API key will effectively start communication with Netmera servers. Netmera will store any operation until it has an API key

        Setting API key to null or empty string will stop all network operations, and all pending operations will be stored until a valid API key is set again.

        Parameters:
        apiKey - Application specific API key gathered from Netmera panel.
      • setBaseUrlWithApiKey

        public static void setBaseUrlWithApiKey​(java.lang.String baseUrl,
                                                java.lang.String apiKey)
        Sets given Netmera SDK API key and changes base API URL to given URL string.

        Calling this method with a valid API key will effectively start communication with Netmera servers. Netmera will store any operation until it has an API key

        Setting API key to null or empty string will stop all network operations, and all pending operations will be stored until a valid API key is set again.

        Please refer to use this method when a custom Netmera domain is defined to your application.

        Parameters:
        apiKey - Application specific API key gathered from Netmera panel.
      • turnOffSendingEventAndUserUpdate

        public static void turnOffSendingEventAndUserUpdate​(boolean turnOff)
        Completely turn off sending all events and user data. If a true boolean parameter is passed to this method, NetmeraUser updates and NetmeraEvents will never be sent to server.

        Parameters:
        turnOff - Flag for opt-out user data and events. Default value is false.
      • startDataTransfer

        public static void startDataTransfer()
        Enables event sharing and update user if it has been blocked before.
      • stopDataTransfer

        public static void stopDataTransfer()
        Blocks event sharing and updating user. After this method call startDataTransfer must be called for reactivating.
      • sendEvent

        public static <T extends NetmeraEvent> void sendEvent​(T netmeraEvent)
        Send an event to Netmera servers.

        You can send behavioral actions of your users using this method.

        Rather than accepting unstructured information inside events, SDK requires given event to be a valid subclass of NetmeraEvent class. This approach provides Netmera to verify type of the given event attributes, which is crucial during event analytics operations on Netmera servers.

        Parameters:
        netmeraEvent - An event object which is subclass of NetmeraEvent
      • identifyUser

        public static void identifyUser​(NMUser nmUser)
        Set or update the identifiers of the user in Netmera.

        In order to update attributes of the user, you should use Netmera#updateUserProfile(NMUserProfile)

        Parameters:
        nmUser - NMUser object for setting user related identifiers
      • identifyUser

        public static void identifyUser​(NMUser nmUser,
                                        NMUpdateUserListener listener)
        Set or update the identifiers of the user in Netmera.

        In order to update identifiers of the user, you should use Netmera#updateUserProfile(NMUserProfile)

        Parameters:
        nmUser - NMUser object for setting user related identifiers
        listener - NMUpdateUserListener to receive success or failure callbacks
      • updateUser

        @Deprecated
        public static <T extends NetmeraUser> void updateUser​(T netmeraUser)
        Deprecated.
        Use Netmera#identifyUser(NMUser) for user identification and Netmera#updateUserProfile(NMUserProfile) for updating profile attributes.
        Set or update the attributes of the user in Netmera.

        Parameters:
        netmeraUser - NetmeraUser object for setting user related attributes
      • updateUser

        @Deprecated
        public static <T extends NetmeraUser> void updateUser​(T netmeraUser,
                                                              NMUpdateUserListener listener)
        Deprecated.
        Use Netmera#identifyUser(NMUser) for user identification and Netmera#updateUserProfile(NMUserProfile) for updating profile attributes.
        Set or update the attributes of the user in Netmera.

        Parameters:
        netmeraUser - NetmeraUser object for setting user related attributes
        listener - NMUpdateUserListener to receive success or failure callbacks
      • updateUserProfile

        public static <T extends NMUserProfile> void updateUserProfile​(T userProfile)
        Set or update the attributes of the user in Netmera.

        Parameters:
        userProfile - NMUserProfile object for setting user related attributes
      • updateUserProfile

        public static <T extends NMUserProfile> void updateUserProfile​(T userProfile,
                                                                       NMUpdateUserProfileListener listener)
        Set or update the attributes of the user in Netmera with a listener for the operation result.

        Parameters:
        userProfile - NMUserProfile object containing user-related attributes to be updated
        listener - NMUpdateUserProfileListener to receive success or failure callbacks
      • enablePush

        public static boolean enablePush()
        Enable push notification for this device if system notifications are enabled.

        Push notification is enabled by default but if push notification is disabled via disablePush(), it can be re-enabled via this method.

      • enablePush

        public static void enablePush​(android.app.Activity activity)
        Enable push notification for this device if system notifications are enabled.

        Push notification is enabled by default but if push notification is disabled via disablePush(), it can be re-enabled via this method.

        Parameters:
        activity - Activity request permission if system notifications are disabled below API 33 goes to app settings
      • disablePush

        public static void disablePush()
        Disable push notification for this device.

        This method can be used to prevent Netmera servers to send push notifications to this device.

      • isPushEnabled

        public static boolean isPushEnabled()
        Check push notification state.

        This method checks both system level state and app level state.

        Returns:
        True if both of the states are @code{true}, false otherwise.
      • enablePopupPresentation

        public static void enablePopupPresentation()
        Enable Netmera to present received popups immediately.

        By default, Netmera does not present received popup style notifications automatically.

        Use this method to enable Netmera to automatically present popup style notifications if you previously disabled using disablePopupPresentation() method.

        If a popup style notification has been received during the time at which popup presentation was disabled, it will be shown immediately after you call this method.

        If multiple popup notifications have been received, only the most recent one will be presented.

      • disablePopupPresentation

        public static void disablePopupPresentation()
        Disable Netmera to present received popups.

        By default, Netmera presents received popup style notifications automatically.

        Use this method to disable Netmera to automatically present popup style notifications.

        If any popup notification is received during the time at which presentation is disabled, it will be presented immediately after presentation is enabled again via enablePopupPresentation().

      • handleWebContent

        public static void handleWebContent​(android.webkit.WebView webView)
        Load contents of the web view action of recent push notification in given web view.

        When this method is called, Netmera will immediately load the contents of the web view action inside given WebView object.

        If you need to be notified about WebViewClient.shouldOverrideUrlLoading(WebView, String)} method calls, you should use handleWebContent(WebView, NetmeraWebViewCallback) method.

        Parameters:
        webView - A WebView instance upon which related HTML content will be loaded.
      • handleWebContent

        public static void handleWebContent​(android.webkit.WebView webView,
                                            NetmeraWebViewCallback netmeraWebViewCallback)
        Load contents of the web view action of recent push notification in given web view and delegates WebViewClient.shouldOverrideUrlLoading(WebView, String)} method calls to given callback.

        When this method is called, Netmera will immediately load the contents of the web view action inside given WebView object.

        Parameters:
        webView - A WebView instance upon which related HTML content will be loaded.
        netmeraWebViewCallback - A callback instance which will be called for url loadings
      • handlePushObject

        public static void handlePushObject​(android.app.Activity activity,
                                            NetmeraPushObject netmeraPushObject)
        Perform push object's action or show a simple dialog with action buttons according to push type

        When this method is called, if push object has action buttons, a simple dialog with buttons will be shown. If one of button is clicked by user, its action will be taken. If push object has no action buttons, the action related to object itself will be taken directly.

        Parameters:
        activity - The activity in which dialog will be shown.
        netmeraPushObject - Push object instance to process
      • fetchInbox

        public static void fetchInbox​(NetmeraInboxFilter filter,
                                      NetmeraInbox.NetmeraInboxFetchCallback callback)
        Fetch list of push notifications matching with given filter from Netmera.

        This method will start the fetch process and return immediately. When fetch process is finished, given callback will be called with a NetmeraInbox object or with a non-null NetmeraError object if fetch operation has failed.

        Use returned NetmeraInbox object for future operations on the inbox such as accessing the objects, fetching next pages of the inbox list, and modifying the status of objects.

        Parameters:
        filter - A NetmeraInboxFilter object defining the filter options for the list of push objects to be returned from server.
        callback - A NetmeraInbox.NetmeraInboxFetchCallback to be triggered after fetch process is completed.
        See Also:
        class for the possible filtering options.
      • requestPermissionsForLocation

        public static void requestPermissionsForLocation()
        Request location permissions from user (For Android version level 23 and above).

        Calling this method will trigger OS to present location permission dialog to user. After permissions are granted, location tracking and geofence monitoring will start if they have been configured on Netmera panel.

        You do not need to call this method if your app already has Location permission.

      • requestNotificationPermissions

        public static void requestNotificationPermissions​(android.app.Activity activity)
        This method allows you to get the Push Notification Permissions that come with Android API Level 33 at runtime.
        Parameters:
        activity - Necessary for context
      • checkNotificationPermission

        public static NotificationPermissionStatus checkNotificationPermission​(android.app.Activity activity)
        Checks and returns the user's notification permission status.
        Parameters:
        activity - Necessary for context
        Returns:
        NotificationPermissionStatus enum representing the current permission status.
      • areNotificationsEnabled

        public static boolean areNotificationsEnabled()
        This method is used to query the Push Notification permissions that come with Android API Level 33.
        Returns:
        Always returns true if the application has Build.VERSION.SDK_INT < 33 or if the user grants the necessary permissions. Otherwise false
      • setNetmeraMaxActiveRegions

        public static void setNetmeraMaxActiveRegions​(int netmeraMaxActiveRegions)
        Request maximum active geofence region from user

        If user sets max active regions' number greater than 100 or smaller than 0, it will be set as the default which is 100

        Parameters:
        netmeraMaxActiveRegions - Maximum Netmera active geofence regions
      • onNetmeraPushMessageReceived

        public static void onNetmeraPushMessageReceived​(java.lang.Object remoteMessage)
        This method must be called when the application has its own integration of either FirebaseMessagingService or HmsMessageService. Please consider calling this when application's onMessageReceived(Object remoteMessage) method was triggered by either Firebase Console or Huawei Console.
        Parameters:
        remoteMessage - com.google.firebase.messaging.RemoteMessage or com.huawei.hms.push.RemoteMessage Push notification message, which was caught by either FirebaseMessagingService or HmsMessageService
      • onNetmeraNewToken

        public static void onNetmeraNewToken​(java.lang.String token)
        This method must be called when the application has its own integration of FirebaseMessagingService. Please consider calling this when application's onNewToken(String s) method was triggered by Firebase or HMS.
        Parameters:
        token - Token, which was caught by depending on provider.
      • onNetmeraNewToken

        public static void onNetmeraNewToken​(java.lang.String token,
                                             boolean forceToSend)
        This method must be called when the application has its own integration of FirebaseMessagingService. Please consider calling this when application's onNewToken(String s) method was triggered by Firebase or HMS.
        Parameters:
        token - Token, which was caught by depending on provider.
        forceToSend - Force to send new token to the server.
      • isNetmeraRemoteMessage

        @Deprecated
        public static boolean isNetmeraRemoteMessage​(java.lang.Object remoteMessage)
        Deprecated.
        Use isNetmeraRemoteMessage(Map) for more straightforward way to check the incoming RemoteMessage.
        Parameters:
        remoteMessage - Push notification message, which was sent by FCM or HMS
      • isNetmeraRemoteMessage

        public static boolean isNetmeraRemoteMessage​(java.util.Map<java.lang.String,​java.lang.String> dataOfRemoteMessage)
        This method should be called for obtaining, if the incoming RemoteMessage is sent from the Netmera Console. True - If RemoteMessage belongs Netmera Console False - For other sources
        Parameters:
        dataOfRemoteMessage - Push notification message, which was sent by FCM or HMS, If called from FCM service pass remoteMessage.data, If called from HMS service pass remoteMessage.dataOfMap.
      • setNetmeraHeaders

        public static void setNetmeraHeaders​(android.content.ContentValues headerValueSet)
        This method should be called to add custom headers to Netmera Requests for hybrid platforms. Usage of this method is not obligatory.
        Parameters:
        headerValueSet - - Header Map, which holds key-value pairs
      • updateAll

        public static void updateAll​(int inboxStatus,
                                     NetmeraInbox.NetmeraInboxStatusCallback callback)
        Update status of all push objects in the inbox.

        Calling this method will update the inbox status of all push objects, and result will be informed via given NetmeraInbox.NetmeraInboxStatusCallback object. A null error value means operation succeeded.

        Setting multiple status options to status parameter will result in an immediate error.

        Parameters:
        inboxStatus - Status option to be set upon given push objects.
        callback - A NetmeraInbox.NetmeraInboxStatusCallback to be triggered after update process is completed.
      • updateStatusByCategories

        public static void updateStatusByCategories​(int inboxStatus,
                                                    java.util.List<java.lang.String> categoryList,
                                                    NetmeraInbox.NetmeraInboxStatusCallback callback)
        Update status of the push objects which are in the given categories.

        Calling this method will update the inbox status of push objects which are in the given categories, and result will be informed via given NetmeraInbox.NetmeraInboxStatusCallback object. A null error value means operation succeeded.

        Setting multiple status options to status parameter will result in an immediate error.

        Parameters:
        inboxStatus - Status option to be set upon to all push objects which are in the given categories.
        categoryList - The list of categories whose push objects will be updated.
        callback - A NetmeraInbox.NetmeraInboxStatusCallback to be triggered after update process is completed.
      • handleInteractiveAction

        public static void handleInteractiveAction​(android.content.Context context,
                                                   NetmeraInteractiveAction interactiveAction)
        Perform push object's interactive actions

        When this method is called, action according to push object's interactive action will be triggered/shown. (For example triggering of a deeplink or showing webpage upon button click.)

        Parameters:
        context - Activity context will be accepted.
        interactiveAction - Push object's NetmeraInteractiveAction.
      • getCurrentExternalId

        public static java.lang.String getCurrentExternalId()
        Returns the user's external Id if it has already been set.
        Returns:
        String external id of the user
      • setUserCategoryPreference

        public static void setUserCategoryPreference​(int categoryId,
                                                     java.lang.Boolean categoryEnabled,
                                                     NMCategoryPreferenceSetCallback listener)
        Update enable status of user's category preference according to the given category id.
        Parameters:
        categoryId - Category preference id, which will be updated.
        categoryEnabled - Status of the category preference. True stands for enable.
        listener - NMCategoryPreferenceSetCallback Needed for listening network results.
      • getInboxCountForStatus

        public static void getInboxCountForStatus​(NMInboxStatusCountFilter filter,
                                                  NMInboxCountResultListener listener)
        Returns the number of inbox messages according to the parameters given with the NMInboxStatusCountFilter.
        Parameters:
        filter - NMInboxStatusCountFilter
        listener - NMInboxCountResultListener Needed for listening network results.
      • fetchCoupons

        public static void fetchCoupons​(int page,
                                        int max,
                                        NMFetchCouponsResultListener listener)
        Returns the coupons according to the parameters given with the NMFetchCouponsResultListener.
        Parameters:
        page - the page number [0...Max_Int]
        max - maximum count [1...Max_Int]
      • getUserCategoryPreferenceList

        public static void getUserCategoryPreferenceList​(NMCategoryPreferenceFetchCallback listener)
        Fetch the category preference list of a single user.
        Parameters:
        listener - NMCategoryPreferenceFetchCallback Needed for listening network results. NMCategoryPreference list will be returned onSuccess method callback.
      • initCrashTracker

        @Deprecated
        public static void initCrashTracker()
        Deprecated.
        This method should not be used, as the crash tracker functionality has been removed from the SDK.
      • logException

        @Deprecated
        public static void logException​(java.lang.Exception e)
        Deprecated.
        This method should not be used, as the crash tracker functionality has been removed from the SDK.
      • setNetmeraEncrypter

        public static void setNetmeraEncrypter​(NetmeraEncrypter netmeraEncrypter)
      • registerForPushActions

        public static void registerForPushActions​(NMPushActionCallbacks nmPushActionCallbacks)
      • registerForNetmeraInAppmessageActions

        public static void registerForNetmeraInAppmessageActions​(NMInAppMessageActionCallbacks nmInAppMessageActionCallbacks)
      • registerForNetmeraWebWidgetCallbacks

        public static void registerForNetmeraWebWidgetCallbacks​(NMWebWidgetCallbacks nmWebWidgetCallbacks)
      • registerForNetmeraDeeplinkCallback

        public static void registerForNetmeraDeeplinkCallback​(NMDeeplinkCallback nmDeeplinkCallback)
      • sendScreenErrorEvent

        public static void sendScreenErrorEvent​(java.lang.String errorTitle,
                                                java.lang.String errorMessage)
      • registerProviderComponent

        public static void registerProviderComponent​(NMProviderComponent nmProviderComponent,
                                                     NMProviderRegistrationCallback registrationCallback)
      • setEmailPermission

        public static void setEmailPermission​(boolean isAllowed)
        Sets the email permission for the user
        Parameters:
        isAllowed - permission to be set
      • getEmailPermission

        public static void getEmailPermission​(NMPermissionResultListener listener)
        Returns the email permission for the user
        Parameters:
        listener - NMPermissionResultListener to receive success or failure callbacks
      • setSmsPermission

        public static void setSmsPermission​(boolean isAllowed)
        Sets the SMS permission for the user
        Parameters:
        isAllowed - permission to be set
      • getSmsPermission

        public static void getSmsPermission​(NMPermissionResultListener listener)
        Returns the SMS permission for the user
        Parameters:
        listener - NMPermissionResultListener to receive success or failure callbacks