Class SORIAudioRecognizer

  • All Implemented Interfaces:

    
    public class SORIAudioRecognizer
    
                        

    The primary entry point for the SORI SDK that handles audio recognition.

    • Constructor Detail

      • SORIAudioRecognizer

        SORIAudioRecognizer(String applicationId, String secretKey)
    • Method Detail

      • setConfig

         final Unit setConfig(SORIConfig config)

        Configure network handling behavior for the SORI SDK. This allows customization of how the SDK handles network unavailability.

        Parameters:
        config - The configuration for network handling
      • setListener

         final Unit setListener(Context ctx, ISORIListener listener)

        Set the listener interface for SORI SDK events. It helps to subscribe to the useful events like campaign found, service state changes, etc.

        Parameters:
        ctx - The context from which the service is started.
        listener - The listener for SORI SDK events.
      • getServiceIntent

         final Intent getServiceIntent(Context ctx, String title, String body, Integer icon)

        Creates an intent to start the SORI Audio Recognition Service. This intent can be used to start the service from an activity or another component. example usage:

        val intent = SORIAudioRecognizer.getServiceIntent(this)
        this.startForegroundService(intent)
        Parameters:
        ctx - The context from which the service is started.
        title - The title of the notification.
        body - The body of the notification.
        icon - The icon resource ID for the notification.
        Returns:

        An intent to start the SORI Audio Recognition Service.

      • startRecognition

         final Unit startRecognition(Context ctx, String title, String body, Integer icon)

        Starts the SORI Audio Recognition Service. Repeated calls while a start is pending or recognition is active return without changing the notification, listener, configuration, or capture session, including across instances. Use setListener to attach a listener and setConfig to change configuration explicitly. example usage:

        val recognizer = SORIAudioRecognizer("your_application_id", "your_secret_key")
        recognizer.startRecognition(this)
        Parameters:
        ctx - The context from which the service is started.
        title - The title of the foreground notification.
        body - The body of the foreground notification.
        icon - The icon resource ID for the foreground notification.
      • stopRecognition

         final Unit stopRecognition(Context ctx)

        Stops the SORI Audio Recognition Service. example usage:

        recognizer.stopRecognition(this)
        Parameters:
        ctx - The context from which the service is stopped.
      • cleanup

         final Unit cleanup(Context ctx)

        Clean up resources including EventBus subscription and BroadcastReceiver. This should be called when completely done with the recognizer.

        Parameters:
        ctx - The context used for unregistering receivers
      • clearState

         final Unit clearState(Context ctx)

        Clears the match state of the SORI Audio Recognition Service. This method is useful to reset the state of the service. example usage:

        recognizer.clearState(this)
        Parameters:
        ctx - The context from which the service is cleared.
      • getRemainingServiceTime

         final Long getRemainingServiceTime()

        Gets the remaining service runtime in milliseconds before the Android 15 time limit. Returns -1 if there's no time limit (pre-Android 15), if the service is not running, or if the service is not bound.

        Returns:

        The remaining time in milliseconds, or -1 if not applicable

      • isServiceApproachingTimeLimit

         final Boolean isServiceApproachingTimeLimit()

        Checks if the service is approaching the Android 15 time limit. Returns true if less than 5 minutes remain before the time limit. Returns false if the service is not running, not bound, or on pre-Android 15 devices.

        Returns:

        true if approaching time limit, false otherwise

      • handleActionURL

         final Unit handleActionURL(Context ctx, URL url)

        Visits the actual action URL that retrieves from the API Server.

        Although default browser in user's device can handle it automatically but, doing this manually can be helpful on the reasons below:

        • The bounce URL does not shown to the user. (preventing flashing)

        • Application can handle their own schema handler.

        • Seamlessly track user activities without annoying.

        Parameters:
        ctx - The context from which the service is started.
        url - The action URL from SORICampaign.
      • handleActionURL

         final Unit handleActionURL(Context ctx, String url)

        Visits the actual action URL that retrieves from the API Server.

        Although default browser in user's device can handle it automatically but, doing this manually can be helpful on the reasons below:

        • The bounce URL does not shown to the user. (preventing flashing)

        • Application can handle their own schema handler.

        • Seamlessly track user activities without annoying.

        Parameters:
        ctx - The context from which the service is started.
        url - The action URL from SORICampaign.
      • handleActionURL

         final Unit handleActionURL(Context ctx, SORICampaign campaign)

        Visits the actual action URL that retrieves from the API Server.

        Although default browser in user's device can handle it automatically but, doing this manually can be helpful on the reasons below:

        • The bounce URL does not shown to the user. (preventing flashing)

        • Application can handle their own schema handler.

        • Seamlessly track user activities without annoying.

        Parameters:
        ctx - The context from which the service is started.
        campaign - The SORICampaign object that contains the action URL.
      • updateDatabase

         final UpdateResult updateDatabase(Context ctx)

        Updates the audio recognition database by checking for and downloading new audiopacks. This method can be called independently of the startRecognition method.

        The method performs the following steps:

        • Authenticates with the SORI API

        • Checks if a database update is available

        • Downloads the new audiopack if available

        • Applies the update immediately if the recognition service is running

        • Stores the update for later application if the service is not running

        example usage:

        val recognizer = SORIAudioRecognizer("your_application_id", "your_secret_key")
        CoroutineScope(Dispatchers.Main).launch {
            val result = recognizer.updateDatabase(this@MainActivity)
            if (result.success) {
                if (result.updateAvailable) {
                    Log.d("SORI", "Database updated to version: ${result.currentVersion}")
                } else {
                    Log.d("SORI", "Database is already up to date")
                }
            } else {
                Log.e("SORI", "Database update failed: ${result.errorMessage}")
            }
        }
        Parameters:
        ctx - The context from which the update is requested.
        Returns:

        UpdateResult containing the status of the update operation.