本文整理了Java中com.androidnetworking.AndroidNetworking
类的一些代码示例,展示了AndroidNetworking
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AndroidNetworking
类的具体详情如下:
包路径:com.androidnetworking.AndroidNetworking
类名称:AndroidNetworking
[英]AndroidNetworking entry point. You must initialize this class before use. The simplest way is to just do {#code AndroidNetworking.initialize(context)}.
[中]AndroidNetworking入口点。在使用之前必须初始化该类。最简单的方法就是执行{#编写AndroidNetworking.initialize(context)}。
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@Override
public void onCreate() {
super.onCreate();
appInstance = this;
AndroidNetworking.initialize(getApplicationContext());
AndroidNetworking.enableLogging();
AndroidNetworking.setConnectionQualityChangeListener(new ConnectionQualityChangeListener() {
@Override
public void onChange(ConnectionQuality currentConnectionQuality, int currentBandwidth) {
Log.d(TAG, "onChange: currentConnectionQuality : " + currentConnectionQuality + " currentBandwidth : " + currentBandwidth);
}
});
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
public void getCurrentConnectionQuality(View view) {
Log.d(TAG, "getCurrentConnectionQuality : " + AndroidNetworking.getCurrentConnectionQuality() + " currentBandwidth : " + AndroidNetworking.getCurrentBandwidth());
}
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@Override
public void onCreate() {
super.onCreate();
appInstance = this;
AndroidNetworking.initialize(getApplicationContext());
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
AndroidNetworking.setBitmapDecodeOptions(options);
AndroidNetworking.enableLogging();
AndroidNetworking.setConnectionQualityChangeListener(new ConnectionQualityChangeListener() {
@Override
public void onChange(ConnectionQuality currentConnectionQuality, int currentBandwidth) {
Log.d(TAG, "onChange: currentConnectionQuality : " + currentConnectionQuality + " currentBandwidth : " + currentBandwidth);
}
});
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@SuppressWarnings("unchecked")
public void testSynchronousJSONArrayGetRequest() throws InterruptedException, JSONException {
server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
ANResponse<JSONArray> response = request.executeForJSONArray();
JSONObject jsonObject = response.getResult().getJSONObject(0);
assertEquals("Amit", jsonObject.getString("firstName"));
assertEquals("Shekhar", jsonObject.getString("lastName"));
}
代码示例来源:origin: MindorksOpenSource/android-mvp-architecture
@Override
public void onCreate() {
super.onCreate();
mApplicationComponent = DaggerApplicationComponent.builder()
.applicationModule(new ApplicationModule(this)).build();
mApplicationComponent.inject(this);
AppLogger.init();
AndroidNetworking.initialize(getApplicationContext());
if (BuildConfig.DEBUG) {
AndroidNetworking.enableLogging(Level.BODY);
}
CalligraphyConfig.initDefault(mCalligraphyConfig);
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@SuppressWarnings("unchecked")
public void testSynchronousJSONArrayPostRequest() throws InterruptedException, JSONException {
server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
ANRequest request = AndroidNetworking.post(server.url("/").toString())
.addBodyParameter("fistName", "Amit")
.addBodyParameter("lastName", "Shekhar")
.build();
ANResponse<JSONArray> response = request.executeForJSONArray();
JSONObject jsonObject = response.getResult().getJSONObject(0);
assertEquals("Amit", jsonObject.getString("firstName"));
assertEquals("Shekhar", jsonObject.getString("lastName"));
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@SuppressWarnings("unchecked")
public void testSynchronousJSONArrayMultipartRequest() throws InterruptedException, JSONException {
server.enqueue(new MockResponse().setBody("[{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}]"));
ANRequest request = AndroidNetworking.upload(server.url("/").toString())
.addMultipartParameter("key", "value")
.build();
ANResponse<JSONArray> response = request.executeForJSONArray();
JSONObject jsonObject = response.getResult().getJSONObject(0);
assertEquals("Amit", jsonObject.getString("firstName"));
assertEquals("Shekhar", jsonObject.getString("lastName"));
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
/**
* Method to enable logging
*/
public static void enableLogging() {
enableLogging(Level.BASIC);
}
代码示例来源:origin: nanchen2251/RxJava2Examples
@Override
public void onCreate() {
super.onCreate();
AndroidNetworking.initialize(getApplicationContext());
}
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@SuppressWarnings("unchecked")
public void testSyncResponseBodyGet() throws InterruptedException, IOException {
server.enqueue(new MockResponse().setBody("data"));
ANRequest request = AndroidNetworking.get(server.url("/").toString()).build();
ANResponse<Response> response = request.executeForOkHttpResponse();
assertEquals("data", response.getResult().body().string());
}
代码示例来源:origin: MindorksOpenSource/android-mvp-interactor-architecture
@Override
public void onCreate() {
super.onCreate();
mApplicationComponent = DaggerApplicationComponent.builder()
.applicationModule(new ApplicationModule(this)).build();
mApplicationComponent.inject(this);
AppLogger.init();
AndroidNetworking.initialize(getApplicationContext());
if (BuildConfig.DEBUG) {
AndroidNetworking.enableLogging(Level.BODY);
}
CalligraphyConfig.initDefault(mCalligraphyConfig);
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@SuppressWarnings("unchecked")
public void testSyncResponseBodyPost() throws InterruptedException, IOException {
server.enqueue(new MockResponse().setBody("data"));
ANRequest request = AndroidNetworking.post(server.url("/").toString())
.addBodyParameter("fistName", "Amit")
.addBodyParameter("lastName", "Shekhar")
.build();
ANResponse<Response> response = request.executeForOkHttpResponse();
assertEquals("data", response.getResult().body().string());
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@SuppressWarnings("unchecked")
public void testSyncResponseBodyMultipart() throws InterruptedException, IOException {
server.enqueue(new MockResponse().setBody("data"));
ANRequest request = AndroidNetworking.upload(server.url("/").toString())
.addMultipartParameter("key", "value")
.build();
ANResponse<Response> response = request.executeForOkHttpResponse();
assertEquals("data", response.getResult().body().string());
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
public void testObjectGetRequest() throws InterruptedException {
server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
final AtomicReference<String> firstNameRef = new AtomicReference<>();
final AtomicReference<String> lastNameRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.get(server.url("/").toString())
.build()
.getAsObject(User.class, new ParsedRequestListener<User>() {
@Override
public void onResponse(User user) {
firstNameRef.set(user.firstName);
lastNameRef.set(user.lastName);
latch.countDown();
}
@Override
public void onError(ANError anError) {
assertTrue(false);
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals("Amit", firstNameRef.get());
assertEquals("Shekhar", lastNameRef.get());
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@Override
public void onCreate() {
super.onCreate();
appInstance = this;
AndroidNetworking.initialize(getApplicationContext());
AndroidNetworking.enableLogging();
AndroidNetworking.setConnectionQualityChangeListener(new ConnectionQualityChangeListener() {
@Override
public void onChange(ConnectionQuality currentConnectionQuality, int currentBandwidth) {
Log.d(TAG, "onChange: currentConnectionQuality : " + currentConnectionQuality + " currentBandwidth : " + currentBandwidth);
}
});
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
public void testObjectPostRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.post(server.url("/").toString())
.addBodyParameter("fistName", "Amit")
.addBodyParameter("lastName", "Shekhar")
.build()
.getAsObject(User.class, new ParsedRequestListener<User>() {
@Override
public void onResponse(User user) {
assertTrue(false);
}
@Override
public void onError(ANError anError) {
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
public void getCurrentConnectionQuality(View view) {
Log.d(TAG, "getCurrentConnectionQuality : " + AndroidNetworking.getCurrentConnectionQuality() + " currentBandwidth : " + AndroidNetworking.getCurrentBandwidth());
}
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
public void testResponseBodyAndObjectMultipart() throws InterruptedException {
server.enqueue(new MockResponse().setBody("{\"firstName\":\"Amit\", \"lastName\":\"Shekhar\"}"));
final AtomicReference<String> firstNameRef = new AtomicReference<>();
final AtomicReference<String> lastNameRef = new AtomicReference<>();
final AtomicReference<Boolean> responseBodySuccess = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.upload(server.url("/").toString())
.addMultipartParameter("key", "value")
.setExecutor(Executors.newSingleThreadExecutor())
.build()
.getAsOkHttpResponseAndObject(User.class,
new OkHttpResponseAndParsedRequestListener<User>() {
@Override
public void onResponse(Response okHttpResponse, User user) {
firstNameRef.set(user.firstName);
lastNameRef.set(user.lastName);
responseBodySuccess.set(okHttpResponse.isSuccessful());
latch.countDown();
}
@Override
public void onError(ANError anError) {
assertTrue(false);
}
});
assertTrue(latch.await(2, SECONDS));
assertTrue(responseBodySuccess.get());
assertEquals("Amit", firstNameRef.get());
assertEquals("Shekhar", lastNameRef.get());
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
public void prefetch(View view) {
AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.setTag(this)
.setPriority(Priority.LOW)
.build()
.setAnalyticsListener(new AnalyticsListener() {
@Override
public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) {
Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis);
Log.d(TAG, " bytesSent : " + bytesSent);
Log.d(TAG, " bytesReceived : " + bytesReceived);
Log.d(TAG, " isFromCache : " + isFromCache);
}
})
.prefetch();
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
public void testObjectListPostRequest404() throws InterruptedException {
server.enqueue(new MockResponse().setResponseCode(404).setBody("data"));
final AtomicReference<String> errorDetailRef = new AtomicReference<>();
final AtomicReference<String> errorBodyRef = new AtomicReference<>();
final AtomicReference<Integer> errorCodeRef = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
AndroidNetworking.post(server.url("/").toString())
.addBodyParameter("fistName", "Amit")
.addBodyParameter("lastName", "Shekhar")
.build()
.getAsObjectList(User.class, new ParsedRequestListener<List<User>>() {
@Override
public void onResponse(List<User> userList) {
assertTrue(false);
}
@Override
public void onError(ANError anError) {
errorBodyRef.set(anError.getErrorBody());
errorDetailRef.set(anError.getErrorDetail());
errorCodeRef.set(anError.getErrorCode());
latch.countDown();
}
});
assertTrue(latch.await(2, SECONDS));
assertEquals(ANConstants.RESPONSE_FROM_SERVER_ERROR, errorDetailRef.get());
assertEquals("data", errorBodyRef.get());
assertEquals(404, errorCodeRef.get().intValue());
}
内容来源于网络,如有侵权,请联系作者删除!