Setup SDK
Android PacketSDK Integration Guide
Overview
This guide is intended for application developers who want to monetize their Android apps using the Packet SDK. Packet SDK supports Android native apps written in Kotlin and Java.
Integrating the Packet SDK into your app is the first step to earning revenue. Once integrated, you’ll start seeing revenue in the Packet SDK dashboard within 24 hours.
This document will walk you through the steps required for proper integration. Most apps can be integrated with the Packet SDK in about 15 to 20 minutes.
Compatibility Information
CPU
armeabi, x86, armeabi-v7a, x86_64, arm64-v8a
System
compatible with Android 5.0 and above
Development Environment
Recommended to use Android Studio for development
Preparation
Apply for appkey
Register and login the PacketSDK, go to Dashboard>APP to add your app and get your appkey.
SDK Integration Package Directory Structure
After completing the previous step, download the Android SDK package packet_sdk_android.zip.
Unzip the SDK package to find the following files:
├── SDKDemo: A demo app with the SDK already integrated. You can use this demo to understand how to integrate the SDK. Make sure to test the demo first to understand how the SDK works.
├── libs
│ └── packet_sdk_v***.aar: The obfuscated AAR file.
Installation
Copy packet_sdk_v***.aar to the libs directory of your project.
my-application ├── app │ ├── libs │ │ ├── packet_sdk_v***.aarSet the libs path in the gradle file.
dependencies {
implementation(files("libs/packet_sdk_v***.aar"))
}dependencies {
implementation files('libs/packet_sdk_v***.aar')
}Example files structure:
my-application
├── app
│ ├── libs
│ │ ├── packet_sdk_v***.aar
│ ├── src
│ │ ├── main
│ │ └── AndroidManifest.xml
│ └── build.gradle.kts
├── gradle.properties
├── gradlew
...SDK setup
SDK requires internet connectivity to work. To allow your app to use internet connection add following permission to AndroidManifest.xml file.
<uses-permission android:name="android.permission.INTERNET" \>Configure SDK settings right after initializing the SDK, but before calling the PacketSdk.start() function.
import android.app.Application
import com.packet.sdk.PacketSdk
class App : Application() {
override fun onCreate() {
super.onCreate()
//init sdk with your key
PacketSdk.initialize(this, "app_key")
//enable logging
PacketSdk.setEnableLogging(true)
}
}import android.app.Application;
import com.packet.sdk.PacketSdk;
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
//init sdk with your key
PacketSdk.initialize(this, "app_key");
//enable logging
PacketSdk.setEnableLogging(true);
}
}Declare your Application in manifest and set usesCleartextTraffic="true"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.debby.tunnel_sdk">
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/sun"
android:label="@string/app_name"
android:roundIcon="@mipmap/sun"
android:supportsRtl="true"
android:theme="@style/Theme.Tunnel_sdk"
android:usesCleartextTraffic="true">
</application>
Start SDK
import android.app.Activity
import com.packet.sdk.PacketSdk
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//start sdk
PacketSdk.start()
}
}import android.app.Activity;
import com.packet.sdk.PacketSdk;
public class MainActivity extends Activity {
@Override
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//start sdk
PacketSdk.start();
}
}Logging
Call PacketSdk.setEnableLogging(true) in order to enable logging to logcat.
Status monitor
import android.app.Activity
import com.packet.sdk.PacketSdk
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
PacketSdk.setStatusListener { code: Int, msg: String? ->
//status code and msg
}
// ...
}
}import android.app.Activity;
import com.packet.sdk.PacketSdk;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PacketSdk.setStatusListener((code, msg) -> {
//status code and msg
});
// ...
}
}Stop SDK
Call PacketSdk.stop() in order to stop SDK.
SDK API
package com.packet.sdk;
import android.content.Context;
public class PacketSdk {
/**
* First function to call for SDK. Prepares SDK for configuration and use.
* Uses [context] to prepare SDK for use.
* appKey.
*/
public static void initialize(Context context, String appKey);
/**
* Sets whether to enable logcat logging
* Tag is PacketSdk
*/
public static void setEnableLogging(boolean enableLogging);
/**
* Allows to set listener to monitor sdk status.
*/
public static void setStatusListener(OnStatusListener onStatusListener);
/**
* Starts SDK if user has given the consent, otherwise does nothing.
* Pass [apiKey] that you received via dashboard for your app.
*/
public static void start();
/**
* Stops SDK if it's running.
*/
public static void stop();
}Status Value Description
100
Starting...
101
Get server fail.
102
Connect fail.
200
Connect success.
Once you've received connect success. in the callback function, you will start seeing devices data and revenue in PacketSDK Dashboard in 24 hours.
Last updated