Android Snooper is a library which helps in debugging issues while running the applications on android devices. One of the basic features provided includes HTTP inspection, which observes all the HTTP calls made by the app. When the device is shaked, history of all the HTTP requests is presented with their responses and allows search, copy and sharing of the request/response. This library is inspired by the Network Request History
feature of FLEX app for iOS.
Android Snooper works on the interceptor pattern which is supported by almost every HTTP client. All you need to do is initialize Android Snooper using AndroidSnooper.init(this);
statement in your Application class and set an instance of SnooperInterceptor
to the list of your network interceptors.
As of now Snooper supports the interceptors for the following libraries:
Didn't get your HTTP client's name in the list? No worries, You can still write your own implementation by using Android Snooper's
core module and let Android Snooper know about the request being made. Below is given a dummy implementation.
AndroidSnooper androidSnooper = AndroidSnooper.getInstance();
HttpCall httpCall = new HttpCall.Builder()
.withUrl(httpRequest.getUrl())
.withPayload(httpRequest.getRequestPayload())
.withMethod(httpRequest.getMethod())
.withResponseBody(httpResponse.getResponseBody())
.withStatusCode(httpResponse.getRawStatusCode())
.withStatusText(httpResponse.getStatusCode())
.withRequestHeaders(httpRequest.getHeaders())
.withResponseHeaders(httpResponse.getHeaders())
.build();
androidSnooper.record(httpCall);
The above implementation ought to be part of your custom interceptor where you will have access to the required Request
and Response
object to jot down the required data for Android Snooper to work properly.
Warning: Android Snooper records each and every HTTP call intercepted by it. The sole purpose of Android snooper is to help in debugging, hence only Debug or QA builds are the perfect candidates for integrating the library. Sensitive information such as Auth Tokens, Headers, etc are not supposed to be exposed and hence production apps should not integrate the library.
repositories {
mavenCentral()
}
// when using Android Snooper's core module
compile ('com.github.jainsahab:Snooper:1.5.5@aar'){
transitive = true
}
// Android Snooper library for "Spring Android Rest Template"
compile ('com.github.jainsahab:Snooper-Spring:1.5.5@aar'){
transitive = true
}
// Android Snooper library for "Square's Okhttp"
compile ('com.github.jainsahab:Snooper-Okhttp:1.5.5@aar'){
transitive = true
}
Snapshot versions are available in Sonatype's snapshots repository.
If you would like to contribute code to AndroidSnooper
you can do so by forking the repository and create a Pull request. You can also create an Issue to report bugs or features that you want to see in AndroidSnooper
library.
This library uses:
- Icons made by Madebyoliver, Freepik and Gregor Cresnar from www.flaticon.com is licensed by CC 3.0 BY.
Copyright (C) 2017 Prateek Jain
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.