This is an example Android application demonstrating how to integrate and use the Diode SDK in your Android projects.
This example app shows how to:
- Add the Diode SDK as a dependency to your Android project
- Initialize the SDK
- Connect to Diode network peers
- Send and receive messages through the Diode network
- Android Studio with Android SDK
- The Diode SDK library (AAR file or Maven dependency)
There are several ways to add the Diode SDK to your Android project. Choose the method that best fits your workflow.
If the SDK is published to a Maven repository (Maven Central, JitPack, or your private repository), add the SDK as a Gradle dependency in your app module's build.gradle:
dependencies {
implementation 'io.diode:sdk:1.0.0'
}Add the following dependency to your dependencies block to integrate the library into your Android app:
dependencies {
// Other dependencies...
implementation 'io.diode:sdk:1.0.0'
}Make sure your build.gradle includes the repository where the SDK is hosted:
repositories {
google()
mavenCentral()
// Add your Maven repository here if using a private repo
}If you've built the SDK locally and published it to your local Maven repository using ./gradlew publishToMavenLocal, you can use the same Maven coordinates:
repositories {
mavenLocal() // Include local Maven repository
}
dependencies {
implementation 'io.diode:sdk:1.0.0'
}Download the AAR, place it in your project's libs directory, and configure your build script to treat it as a library dependency.
-
Get the AAR file: Build the SDK from the diode_android_sdk project:
cd ../diode_android_sdk ./gradlew :app:assembleReleaseThis creates
app/build/outputs/aar/app-release.aar -
Copy the AAR to your example app's
libsdirectory:cp ../diode_android_sdk/app/build/outputs/aar/app-release.aar app/libs/diode-sdk-release.aar
-
Add the dependency in
app/build.gradle:dependencies { implementation files('libs/diode-sdk-release.aar') }
Or if you want to reference it by name:
dependencies { implementation(name: 'diode-sdk-release', ext: 'aar') }
If using the named approach, also add:
repositories { flatDir { dirs 'libs' } }
- Open the project in Android Studio
- Sync Gradle files to download dependencies
- Build and run the app on a device or emulator
The example app demonstrates basic SDK usage:
import io.diode.sdk.Bridge
// Initialize the SDK
val bridge = Bridge(applicationContext)
// Set up callbacks
bridge.onMessageReceived = { data ->
// Handle received messages
val decoded = String(Base64.decode(data, Base64.DEFAULT))
// Process decoded message
}
bridge.onConnectionStatusChanged = { connected ->
// Handle connection status changes
if (connected) {
// Connected to peer
} else {
// Disconnected from peer
}
}
// Connect to a Diode peer
bridge.connect("0x389eba94b330140579cdce1feb1a6e905ff876e6", 5000)
// Send a message
bridge.sendMessage("Hello, Diode!")
// Disconnect
bridge.disconnect()diode_android_example/
├── app/
│ ├── libs/ # Place AAR files here (Option 3)
│ │ └── diode-sdk-release.aar
│ ├── src/main/
│ │ ├── java/io/diode/example/
│ │ │ └── MainActivity.kt # Example usage of the SDK
│ │ ├── res/ # App resources
│ │ └── AndroidManifest.xml
│ └── build.gradle # App dependencies
├── build.gradle # Root build file
└── settings.gradle # Project settings
- Ensure the SDK dependency is properly configured (see above)
- Open the project in Android Studio
- Sync Gradle files
- Build the APK:
Or build a release APK:
./gradlew assembleDebug
./gradlew assembleRelease
- Connect an Android device or start an emulator
- Run the app from Android Studio, or install the APK:
./gradlew installDebug
- If using Maven coordinates: Ensure the repository is correctly configured and the SDK version exists
- If using local AAR: Verify the AAR file is in the
libsdirectory and the dependency is correctly specified inbuild.gradle - If using local Maven: Run
./gradlew publishToMavenLocalin the SDK project first
- Ensure all SDK prerequisites are met (see SDK README)
- Check that the SDK was built successfully
- Verify Android SDK and build tools versions match requirements
- Check logcat for detailed error messages
- Ensure the device/emulator has internet permissions
- Verify the Diode peer address and port are correct
If a SOCKS server is running on the remote Diode peer, you can use it as a proxy to connect to other internet locations. This enables you to route your internet traffic through the Diode network, providing privacy and access to services through the peer's network connection.
A SOCKS (Socket Secure) proxy allows you to:
- Route TCP connections through the Diode peer
- Access internet services as if you were on the peer's network
- Bypass network restrictions or access geo-blocked content
- Maintain privacy by routing traffic through the Diode network
To implement SOCKS support in your app:
- Ensure you're connected to a Diode peer that has a SOCKS server running
- Follow the SOCKS Porting Guide for detailed implementation instructions
- Use the SOCKS client to route your app's network traffic through the Diode peer
The SOCKS Porting Guide provides:
- Step-by-step implementation instructions
- Complete code examples for creating a SOCKS client
- HTTP request examples through SOCKS
- Security considerations and best practices
- Testing guidelines
See the SOCKS Porting Guide for complete documentation on implementing SOCKS proxy functionality in your Android app.
If you want to use a WebView that routes all its traffic through a remote SOCKS5 server accessible via the Diode network, see the WebView SOCKS Guide. This guide explains how to:
- Create a local HTTP proxy server that tunnels through the Diode SDK
- Route WebView requests through the Diode SDK's SOCKS connection
- Access internet services through a remote Diode peer's SOCKS server (not on public internet)
- Explore the SOCKS Porting Guide for advanced proxy functionality
- Check the SDK README for detailed SDK documentation
- Customize the example app to fit your use case
See the main SDK project for license information.