Add the dependency to your project Gradle configuration:
Add Massive maven repository to the dependency repositories used by the project. You can find the URL in the downloads page.
It can be defined in different places depending on your project.Common places are:global settings.gradle.kts
Interaction with Massive SDK starts with initializing the MassiveClient in your Activity or Application class. Ensure you do this at the start of the application lifecycle.
class MainActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Initialize MassiveClient MassiveClient.init(API_TOKEN, this) }}
Next, fill in the client options to specify the desired running mode: Foreground or Background service.Foreground service is preferable as it increases the earning potential. You can find more information about the difference in the Technical details.
Before starting the client, obtain user consent for the terms of resource exchange. Please see our launch checklist for additional details.Here is the sample consent screen:Example consent text
To remove ads and get free content, please let Massive use a small amount of your device's free resources and IPaddress to download public web data from the internet.This supports the development of Application and helps us to improve our services.No personal information is collected except your IP address.Your participation is optional, and you may opt out anytime by accessing Settings (see Massive's FAQ for details).Pressing Accept indicates that you agree to Massive's license and privacy policy.
After receiving the user’s consent, start usage using the start() method and created options:
// Check if there is user consent to use Massive and show the dialog if we need to request it.if (!consentHelper.isConsentGiven()) { consentHelper.showConsentDialog( onAccept = { // Start Massive if the user has given consent. MassiveClient.start(massiveOptions) { result -> result.onSuccess { // Handle successful start. }.onFailure { exception -> // Handle start failure. } } }, onDecline = {} )} else { // If the user has already given consent, start Massive directly. MassiveClient.start(massiveOptions) { result -> result.onSuccess { // Handle successful start. }.onFailure { exception -> // Handle start failure. } }}
The new version of the Massive SDK introduces several significant changes aimed at improving usability, performance, and integration flexibility. Here is an overview of the key changes:
Dependency configuration: The dependency configuration process has been streamlined. Instead of manually setting up a local Maven repository, you can now directly add the Massive Maven repository to your project’s Gradle configuration. This simplification reduces setup time and potential errors, ensuring a more efficient integration of the SDK.
Changed package name: The name of the Massive SDK package has changed from com.massive to com.joinmassive.
Changed client interface: The MassiveClient has shifted from using a singleton instance to utilizing static methods. This change simplifies interaction with the SDK, making it more straightforward to initialize and manage the client throughout the application lifecycle.
Options handling: The process of providing options has been moved from the init stage to the start method. This allows for more dynamic configuration, enabling modification of the service options at the time of starting the client rather than during initialization. This separation ensures a quicker initialization process and more flexible configuration management.
Changed behavior of stop: The behavior of the stop method has been enhanced. In the new version, calling stop not only stops the usage but also shuts down the service entirely. This ensures that all operations are cleanly terminated and the service is properly shut down, providing a more robust mechanism for managing the SDK’s lifecycle.
Remote service: The Massive SDK service now runs as a separate process, enhancing the stability and performance of the main application.
// Async state handler.client.listener = object : MassiveClientListener { override fun onStateChange(newState: State) { // Handle changed state. }}...// Current state.client.state
New Version:
// Handle state after the action.MassiveClient.start(massiveOptions) { it.onSuccess { // Handle Started state or query the current state. } it.onFailure { // Handle error. }}// Current state.when (MassiveClinet.state()) { MassiveClient.State.Starting -> { } MassiveClient.State.Started -> { } MassiveClient.State.Stopped -> { }}
Android permissions
Massive SDK defines the following permissions in the manifest file:
android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.FOREGROUND_SERVICE
android.permission.FOREGROUND_SERVICE_DATA_SYNC
android.permission.WAKE_LOCK
These permissions will be automatically added to your app during the build.
Client initialization
Interaction with the SDK always begins with initialization using MassiveClient.init, which requires your API token. This initialization step is crucial and should be performed only once during the application’s lifecycle. Subsequent calls to init will have no effect. Attempting to re-initialize the SDK with a different API token will result in a MassiveReinitException, ensuring that the SDK maintains a single consistent state throughout the app’s runtime.Since the SDK consists of client and service components, initialization can trigger synchronization of their states. To handle this scenario and achieve accurate state tracking, you can pass an additional callback to the init method. This callback will be called in the main thread after synchronization is complete.
User consent before starting the usageBefore starting the usage for the first time (using the start() method), it is mandatory to obtain user consent for the terms of resource exchange. This aligns with user privacy and control principles. Ensure that your application includes a clear and understandable consent mechanism.
if (isUserConsentGiven) { MassiveClient.start(massiveOptions) {}}
Starting and stopping the clientInitialization of the MassiveClient with the init() method does not automatically launch the service or start the usage.It prepares the SDK for use but does not begin its operation.To ensure that the Massive is running, the start() method must be called after initialization and on each application relaunch. The start() method is designed to be idempotent, meaning it is safe to call multiple times. If the service is already started, subsequent calls to start will have no effect, preventing redundant operations.The stop() method is used to stop and kill the service, effectively halting all operations and ensuring that the service is properly terminated. After calling stop(), you can restart the client by calling the start() method again, and it is possible to provide different options for the restart. This flexibility allows you to change the configuration or operational mode of the SDK as needed.
Client options and service typesMassive SDK can operate either as a Background or a Foreground service. The choice depends on your app’s requirements and how you want to manage the SDK’s resource usage.
Foreground Service: Allow Massive to run more and less likely killed by the system but more visible with a customizable notification ensuring the user is aware of the service’s operation.
Running as a Foreground Service increases earning potential.
Background Service: Less intrusive, running silently without user interaction.
Customizing Foreground Service NotificationWhen running as a foreground service, Massive SDK allows customization of the notification displayed to the user.You can set the title, text, and icon of the notification:
Massive library contains a pre-defined drawable icon resource com.joinmassive.sdk.R.drawable.massive_sdk_icon, but you can also provide your own.
Usage trackingThe Massive SDK includes functionality for tracking and retrieving current traffic usage statistics. This allows you to monitor the SDK’s data usage, providing insights into its network activity.The usage method in the MassiveClient class fetches and returns the current traffic usage in bytes. Please check the sample application for an example of how to use the method to retrieve and display the traffic usage statistics.
SDK remote serviceThe latest version of the Massive SDK uses a remote service that is launched as a separate process. This service handles the core operations of the SDK independently of the main application process, providing better performance and stability.
ProGuard rulesMassive SDK AAR embeds required Android ProGuard rules which are applied automatically if you are using the R8 compiler.If you, however, don’t use R8 you have to apply the rules below:
consumer-rules.pro
# Keep the public SDK entities-keep class com.joinmassive.sdk.** { *; }-keep interface com.joinmassive.sdk.** { *; }-keep enum com.joinmassive.sdk.** { *; }-dontwarn org.jetbrains.annotations.**-keep class kotlin.Metadata { *; }# Keep OkHttp3 and Moshi classes-keep class com.squareup.okhttp3.** { *; }-keep interface com.squareup.okhttp3.** { *; }-keep class com.squareup.moshi.** { *; }-keep interface com.squareup.moshi.** { *; }-keepattributes Exceptions,InnerClasses,Signature,Deprecated,*Annotation*,EnclosingMethod