Call HTTP Api from one place and handle multiple things
- Check Internet, if not Display Error message
- Display Log in Log File in device storage (Url, Param, Response)
- Error Handling, if Error Display Message
- Exception Handing, if Exception occurs Display Exception Message
- Display Progress dialog while api calling
- Getting Response Call Back in Activity or fragment
We need to add following class
- WebRequest for HTTP Request
- WebResponse for handle response call back
- Utils for Display Error message, check internet, display progress dialog
- Logger for store log in device storage
- App for handle HTTP request queue
Update your manifest
Add Permission
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
Add line in application tag
android:name=".App"
Call This Method from your Activity or Fragment
HashMap<String, String> params = new HashMap<String, String>();
params.put("username", "sagar.v@gmail.com");
params.put("password", "123456");
params.put("device_platform", "android");
new WebRequest().postMethod(LogInActivity.this, "user/login", params, new WebResponse.Listener<String>() {
@Override
public void onResponse(boolean isSuccess, String response) {
if(isSuccess){
}
}
});
For HTTP Request we need to add volley in gradle
compile 'com.android.volley:volley:1.1.1'