本文整理汇总了Java中com.androidnetworking.AndroidNetworking类的典型用法代码示例。如果您正苦于以下问题:Java AndroidNetworking类的具体用法?Java AndroidNetworking怎么用?Java AndroidNetworking使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AndroidNetworking类属于com.androidnetworking包,在下文中一共展示了AndroidNetworking类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
@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);
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:MvpApp.java
示例2: onCreate
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
mContext = getApplicationContext();
instance = this;
createDirectory();
Extras.init();
mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
metaData = mContext.getSharedPreferences(TAG_METADATA, MODE_PRIVATE);
eqPref = mContext.getSharedPreferences(SAVE_EQ, MODE_PRIVATE);
Extras.getInstance().setwidgetPosition(100);
Extras.getInstance().eqSwitch(false);
mBilling.addPlayStoreListener(new PlayStoreListener() {
@Override
public void onPurchasesChanged() {
Toast.makeText(MusicXApplication.this, "Play Store: purchases have changed!", Toast.LENGTH_LONG).show();
}
});
Fabric.with(this, new Crashlytics());
AndroidNetworking.initialize(this);
}
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:22,代码来源:MusicXApplication.java
示例3: prefetch
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
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();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:OkHttpResponseTestActivity.java
示例4: prefetchDownload
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void prefetchDownload(View view) {
String url = "http://www.colorado.edu/conflict/peace/download/peace_problem.ZIP";
AndroidNetworking.download(url, Utils.getRootDirPath(getApplicationContext()), "file1.zip")
.setPriority(Priority.HIGH)
.setTag(this)
.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();
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:OkHttpResponseTestActivity.java
示例5: onCreate
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
// instance = this;
mApplicationComponent = DaggerApplicationComponent.builder()
.applicationModule(new ApplicationModule(this)).build();
mApplicationComponent.inject(this);
AndroidNetworking.initialize(getApplicationContext());
if (BuildConfig.DEBUG) {
AndroidNetworking.enableLogging(Level.BODY);
}
}
开发者ID:ansh94,项目名称:DailyTech,代码行数:18,代码来源:DailyTechApp.java
示例6: run
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
@Override
public void run() {
while (isNetworkEnabled) {
if (messageQueue.size() > 0) {
final JSONObject object = messageQueue.remove(0);
AndroidNetworking.put(serverURL)
.addJSONObjectBody(object)
.build()
.getAsOkHttpResponse(new OkHttpResponseListener() {
@Override
public void onResponse(Response response) {
//DO Nothing
}
@Override
public void onError(ANError anError) {
Log.e(TAG, "Error: " + anError);
}
});
}
}
}
开发者ID:dji-sdk,项目名称:Android-Bridge-App,代码行数:24,代码来源:DJIRemoteLogger.java
示例7: pushPictureToApi
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void pushPictureToApi(String uId, String base64Picture) {
AndroidNetworking.post(Constants.Api.POST_PICTURE)
.addBodyParameter("uId", uId)
.addBodyParameter("picture", base64Picture)
.setTag("upload perfil picture")
.setPriority(Priority.MEDIUM)
.build()
.getAsOkHttpResponseAndString(new OkHttpResponseAndStringRequestListener() {
@Override
public void onResponse(Response okHttpResponse, String response) {
Log.i(TAG, response);
}
@Override
public void onError(ANError anError) {
Log.e(TAG, anError.getErrorBody());
}
});
}
开发者ID:VitorPoncell,项目名称:poturnoChat,代码行数:20,代码来源:SignupActivity.java
示例8: onCreate
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
@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);
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:MyApplication.java
示例9: onCreate
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
DaggerAppComponent.builder()
.application(this)
.build()
.inject(this);
AppLogger.init();
AndroidNetworking.initialize(getApplicationContext());
if (BuildConfig.DEBUG) {
AndroidNetworking.enableLogging(HttpLoggingInterceptor.Level.BODY);
}
CalligraphyConfig.initDefault(mCalligraphyConfig);
}
开发者ID:MindorksOpenSource,项目名称:android-mvvm-architecture,代码行数:19,代码来源:MvvmApp.java
示例10: testResponseBodyAndObjectListGet
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void testResponseBodyAndObjectListGet() 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.get(server.url("/").toString())
.setExecutor(Executors.newSingleThreadExecutor())
.build()
.getAsOkHttpResponseAndObjectList(User.class,
new OkHttpResponseAndParsedRequestListener<List<User>>() {
@Override
public void onResponse(Response okHttpResponse, List<User> userList) {
firstNameRef.set(userList.get(0).firstName);
lastNameRef.set(userList.get(0).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());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:JacksonGetObjectApiTest.java
示例11: getAnUser
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void getAnUser(View view) {
AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_OBJECT)
.addPathParameter("userId", "1")
.setTag(this)
.setPriority(Priority.LOW)
.setUserAgent("getAnUser")
.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);
}
})
.getAsOkHttpResponseAndObject(User.class, new OkHttpResponseAndParsedRequestListener<User>() {
@Override
public void onResponse(Response okHttpResponse, User user) {
Log.d(TAG, "id : " + user.id);
Log.d(TAG, "firstname : " + user.firstname);
Log.d(TAG, "lastname : " + user.lastname);
if (okHttpResponse.isSuccessful()) {
Log.d(TAG, "onResponse success headers : " + okHttpResponse.headers().toString());
} else {
Log.d(TAG, "onResponse not success headers : " + okHttpResponse.headers().toString());
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:OkHttpResponseTestActivity.java
示例12: createAnUser
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void createAnUser(View view) {
AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER)
.addBodyParameter("firstname", "Suman")
.addBodyParameter("lastname", "Shekhar")
.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);
}
})
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "onResponse object : " + response.toString());
Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
}
@Override
public void onError(ANError error) {
if (error.getErrorCode() != 0) {
// received ANError from server
// error.getErrorCode() - the ANError code from server
// error.getErrorBody() - the ANError body from server
// error.getErrorDetail() - just a ANError detail
Log.d(TAG, "onError errorCode : " + error.getErrorCode());
Log.d(TAG, "onError errorBody : " + error.getErrorBody());
Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
} else {
// error.getErrorDetail() : connectionError, parseError, requestCancelledError
Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
}
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:41,代码来源:ApiTestActivity.java
示例13: makeJSONArrayRequest
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
private void makeJSONArrayRequest() {
AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
.setTag(this)
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.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);
}
})
.getAsJSONArray(new JSONArrayRequestListener() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, "onResponse array : " + response.toString());
}
@Override
public void onError(ANError error) {
if (error.getErrorCode() != 0) {
// received ANError from server
// error.getErrorCode() - the ANError code from server
// error.getErrorBody() - the ANError body from server
// error.getErrorDetail() - just a ANError detail
Log.d(TAG, "onError errorCode : " + error.getErrorCode());
Log.d(TAG, "onError errorBody : " + error.getErrorBody());
Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
} else {
// error.getErrorDetail() : connectionError, parseError, requestCancelledError
Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
}
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:MainActivity.java
示例14: downloadImage
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void downloadImage(final View view) {
String url = "http://i.imgur.com/AtbX9iX.png";
AndroidNetworking.download(url, Utils.getRootDirPath(getApplicationContext()), "image1.png")
.setPriority(Priority.MEDIUM)
.setTag(this)
.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);
}
})
.startDownload(new DownloadListener() {
@Override
public void onDownloadComplete() {
Log.d(TAG, "Image download Completed");
Log.d(TAG, "onDownloadComplete isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
}
@Override
public void onError(ANError error) {
if (error.getErrorCode() != 0) {
// received ANError from server
// error.getErrorCode() - the ANError code from server
// error.getErrorBody() - the ANError body from server
// error.getErrorDetail() - just a ANError detail
Log.d(TAG, "onError errorCode : " + error.getErrorCode());
Log.d(TAG, "onError errorBody : " + error.getErrorBody());
Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
} else {
// error.getErrorDetail() : connectionError, parseError, requestCancelledError
Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
}
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:OkHttpResponseTestActivity.java
示例15: doNotCacheResponse
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void doNotCacheResponse(View view) {
AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.setTag(this)
.setPriority(Priority.LOW)
.doNotCacheResponse()
.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);
}
})
.getAsOkHttpResponseAndJSONArray(new OkHttpResponseAndJSONArrayRequestListener() {
@Override
public void onResponse(Response okHttpResponse, JSONArray response) {
Log.d(TAG, "onResponse object : " + response.toString());
Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
if (okHttpResponse.isSuccessful()) {
Log.d(TAG, "onResponse success headers : " + okHttpResponse.headers().toString());
} else {
Log.d(TAG, "onResponse not success headers : " + okHttpResponse.headers().toString());
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:OkHttpResponseTestActivity.java
示例16: getResponseOnlyFromNetwork
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void getResponseOnlyFromNetwork(View view) {
AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.setTag(this)
.setPriority(Priority.LOW)
.getResponseOnlyFromNetwork()
.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);
}
})
.getAsOkHttpResponseAndJSONArray(new OkHttpResponseAndJSONArrayRequestListener() {
@Override
public void onResponse(Response okHttpResponse, JSONArray response) {
Log.d(TAG, "onResponse object : " + response.toString());
Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
if (okHttpResponse.isSuccessful()) {
Log.d(TAG, "onResponse success headers : " + okHttpResponse.headers().toString());
} else {
Log.d(TAG, "onResponse not success headers : " + okHttpResponse.headers().toString());
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:OkHttpResponseTestActivity.java
示例17: setMaxAgeCacheControl
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void setMaxAgeCacheControl(View view) {
AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.setTag(this)
.setPriority(Priority.LOW)
.setMaxAgeCacheControl(0, TimeUnit.SECONDS)
.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);
}
})
.getAsOkHttpResponseAndJSONArray(new OkHttpResponseAndJSONArrayRequestListener() {
@Override
public void onResponse(Response okHttpResponse, JSONArray response) {
Log.d(TAG, "onResponse object : " + response.toString());
Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
if (okHttpResponse.isSuccessful()) {
Log.d(TAG, "onResponse success headers : " + okHttpResponse.headers().toString());
} else {
Log.d(TAG, "onResponse not success headers : " + okHttpResponse.headers().toString());
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:OkHttpResponseTestActivity.java
示例18: setMaxStaleCacheControl
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void setMaxStaleCacheControl(View view) {
AndroidNetworking.get(ApiEndPoint.BASE_URL + ApiEndPoint.GET_JSON_ARRAY)
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.setTag(this)
.setPriority(Priority.LOW)
.setMaxStaleCacheControl(365, TimeUnit.SECONDS)
.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);
}
})
.getAsOkHttpResponseAndJSONArray(new OkHttpResponseAndJSONArrayRequestListener() {
@Override
public void onResponse(Response okHttpResponse, JSONArray response) {
Log.d(TAG, "onResponse object : " + response.toString());
Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
if (okHttpResponse.isSuccessful()) {
Log.d(TAG, "onResponse success headers : " + okHttpResponse.headers().toString());
} else {
Log.d(TAG, "onResponse not success headers : " + okHttpResponse.headers().toString());
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:OkHttpResponseTestActivity.java
示例19: disableGzipForCustomRequest
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void disableGzipForCustomRequest(View view) {
AndroidNetworking.post(ApiEndPoint.BASE_URL + ApiEndPoint.POST_CREATE_AN_USER)
.addBodyParameter("firstname", "Amit")
.addBodyParameter("lastname", "Shekhar")
.setTag(this)
.setOkHttpClient(new OkHttpClient())
.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);
}
})
.getAsOkHttpResponseAndJSONObject(new OkHttpResponseAndJSONObjectRequestListener() {
@Override
public void onResponse(Response okHttpResponse, JSONObject response) {
Log.d(TAG, "onResponse object : " + response.toString());
Log.d(TAG, "onResponse isMainThread : " + String.valueOf(Looper.myLooper() == Looper.getMainLooper()));
if (okHttpResponse.isSuccessful()) {
Log.d(TAG, "onResponse success headers : " + okHttpResponse.headers().toString());
} else {
Log.d(TAG, "onResponse not success headers : " + okHttpResponse.headers().toString());
}
}
@Override
public void onError(ANError anError) {
Utils.logError(TAG, anError);
}
});
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:OkHttpResponseTestActivity.java
示例20: testResponseBodyAndObjectPost
import com.androidnetworking.AndroidNetworking; //导入依赖的package包/类
public void testResponseBodyAndObjectPost() 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.post(server.url("/").toString())
.addBodyParameter("fistName", "Amit")
.addBodyParameter("lastName", "Shekhar")
.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());
}
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:JacksonPostObjectApiTest.java
注:本文中的com.androidnetworking.AndroidNetworking类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论