Android Open Source - android.app.niuz.io User Service






From Project

Back to project page android.app.niuz.io.

License

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.

Java Source Code

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());
      }
  }
}




Java Source Code List

io.niuz.CategoriesSelectionActivity.java
io.niuz.CompanyInformationLoadingActivity.java
io.niuz.MainActivity.java
io.niuz.NewsCompaniesSelectionActivity.java
io.niuz.NewsHeadersActivity.java
io.niuz.NewsReaderActivity.java
io.niuz.PreMainActivity.java
io.niuz.model.APIRetrievalStatus.java
io.niuz.model.CategoryInformation.java
io.niuz.model.CompanyInformation.java
io.niuz.model.InitUserStatus.java
io.niuz.model.News.java
io.niuz.services.BaseService.java
io.niuz.services.CategoriesSubcategoriesService.java
io.niuz.services.CompaniesService.java
io.niuz.services.NewsService.java
io.niuz.services.PhoneService.java
io.niuz.services.UserService.java