Back to project page android.app.niuz.io.
The source code is released under:
GNU General Public License
If you think the Android project android.app.niuz.io 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 io.niuz.services; //from w w w. j ava 2 s . c om import java.io.ByteArrayOutputStream; import java.io.IOException; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.StatusLine; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONException; import org.json.JSONObject; import android.content.Context; import android.util.Log; public class UserService extends BaseService { public final static String SERVER_LINK_INIT_USER = SERVER_URL + "initUser/"; public final static String SERVER_LINK_DELETE_USR = SERVER_URL + "deleteUser/"; public static boolean initUser(Context context) throws ClientProtocolException, IOException, JSONException { // Setting up the phone number PhoneService.initPhoneNumber(context.getApplicationContext()); String getUrl = SERVER_LINK_INIT_USER + PhoneService.getPhoneNumber(); Log.i("NiuzClientService", "Attempting request: " + getUrl); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(new HttpGet(getUrl)); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK){ ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); JSONObject jsonObject = new JSONObject(out.toString()); return jsonObject.getBoolean("newlyCreated"); } else{ response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } public static void deleteUser(Context context) throws ClientProtocolException, IOException { PhoneService.initPhoneNumber(context.getApplicationContext()); String getUrl = SERVER_LINK_DELETE_USR + PhoneService.getPhoneNumber(); Log.i("NiuzClientService", " request: " + getUrl); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(new HttpGet(getUrl)); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK){ ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); } else{ response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } }