This repo is deprecated, for capture outgoing API calls in Java/Kotlin envinroment, including Android, we recommend
https://github.com/Moesif/moesif-java-okhttp-interceptor
moesif-android is a SDK that automatically captures HTTP traffic such as to your internal APIs or external APIs like Stripe and sends to Moesif for API analytics and log analysis.
This lib requires the use of OkHttp 2.2 or better. OkHttp 3.x is also supported.
The two popular Android networking clients (Volley and Retrofit) support using OkHttp so you are probably fine if using one of these two libs.
If using Retrofit, 1.9 or greater is required. If using Volley, a simple one line change is required to use our MoesifOkHttpXStack.
moesif-android: The core SDK shared across platforms, imported automatically by the below HTTP stack specific modules.
moesif-android-okhttp3: Supports the latest version (3.x) of OkHttp
moesif-android-okhttp2: If you want to stick with OkHttp 2.x for legacy reasons, import this module instead of moesif-android-okhttp3
# Add the jcenter repository, if not present
repositories {
jcenter()
}
dependencies {
compile 'com.moesif.android:moesif-android-okhttp3:1.1.2'
}
If your Android project imports Volley as an unmanaged artifact, you may have to exclude volley as a transitive dependency: Otherwise, you may get duplicate class errors.
# Add the jcenter repository, if not present
repositories {
jcenter()
}
dependencies {
compile ('com.moesif.android:moesif-android-okhttp3:1.1.2') {
exclude group: 'com.android.volley'
}
}
Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.
You can always find your Moesif Application Id at any time by logging into the Moesif Portal, click on the top right menu, and then clicking Installation.
<application>
<!-- Your other code -->
<meta-data
android:name="com.moesif.android.ApplicationId"
android:value="Your Moesif Application Id" />
</application>
import com.moesif.android.MoesifClient;
public final class MyApplicationClass extends Application {
@Override
public void onCreate() {
MoesifClient.initialize(this);
}
}
Add the Moesif MoesifOkHttp3Interceptor when building the Retrofit/OkHttp Client. If you have existing interceptors, you probably want Moesif's interceptor last in the chain to ensure it captures the HTTP call just before going over the wire. See more Info on using OkHttp Interceptors
import com.moesif.android.okhttp3;
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new MoesifOkHttp3Interceptor())
.build();
Pass in a new MoesifOkHttp3Stack object when creating Volley's request queue. See more info on setting up volley
import com.moesif.android.okhttp3;
RequestQueue queue = Volley.newRequestQueue(myContext.getApplicationContext(),
new MoesifOkHttp3Stack());
Follow the previous configuration steps, except a few changes:
# Add the jcenter repository, if not present
repositories {
jcenter()
}
dependencies {
compile 'com.moesif.android:moesif-android-okhttp2:1.1.2'
}
import com.moesif.android.okhttp2;
OkHttpClient myHttpClient new OkHttpClient();
myHttpClient.networkInterceptors().add(new MoesifOkHttp2Interceptor());
import com.moesif.android.okhttp2;
RequestQueue queue = Volley.newRequestQueue(myContext.getApplicationContext(),
new MoesifOkHttp2Stack(new OkHttpClient()));
See LICENSE File for details. The MoesifOkHttp3Stack and MoesifOkHttp2Stack classes, and the entirety of the com.moesif.android.inspector package used by this software have been licensed from non-Moesif sources and modified for use in the library. Please see the relevant source files, and the LICENSE file in the com.moesif.android.inspector package for details.
To view more more documenation on integration options, please visit the Integration Options Documentation.