Back to project page android-http.
The source code is released under:
Apache License
If you think the Android project android-http listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.markom.android.http.loader; //from ww w . j ava2s .c o m import android.content.Context; import android.support.v4.app.LoaderManager.LoaderCallbacks; import com.markom.android.http.exceptions.GsonParsingException; import com.markom.android.http.model.ServiceResponse; /** * Use this loader in order to obitain raw string result from HTTP response. In order to receive result it is needed to * implement {@link LoaderCallbacks} interface with {@link LoaderResponse} type that have {@link String} as generic * parameter. * <p> * Example: * <p> * * <pre> * public class ExampleActivity extends FragmentActivity implements LoaderCallbacks<LoaderResponse<String>> { * * @Override * public Loader<LoaderResponse<String>> onCreateLoader(int id, Bundle bundle) { * RawResponseLoader loader = new RawResponseLaoder(this, url); * // additional loader HTTP setup * return loader; * } * * @Override * public void onLoadFinished(Loader<LoaderResponse<String>> loader, LoaderResponse<String> response) { * // Do something with string response * } * * @Override * public void onLoaderReset(Loader<LoaderResponse<String>> loader) { * } * * }); * </pre> * * @author Marko Milos */ public class RawResponseLoader extends BaseGsonLoader<String> { /** * @see BaseGsonLoader */ public RawResponseLoader(Context context, String url) { super(context, url); } @Override protected ServiceResponse<String> parseServiceResponse(String response) throws GsonParsingException { // We only need response string as data so set passed response as data ServiceResponse<String> serviceResponse = new ServiceResponse<String>(); serviceResponse.setData(response); return serviceResponse; } }