Android Open Source - AndroidCloud Apk Operation






From Project

Back to project page AndroidCloud.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroidCloud 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 com.twlkyao.utils;
//  w ww.j a va2 s . co m
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

import com.twlkyao.utils.FileOperation;
/**
 * Check the apk whether it is in the authorized data base or not.
 * @author Shiyao Qi
 * @date 2014.1.9
 * @email qishiyao2008@126.com
 */
public class ApkOperation {
  
  private String TAG = "ApkOperation";
  private boolean DEBUG = true;
  private LogUtils logUtils = new LogUtils(DEBUG, TAG);
  
  public boolean ApkCheckInfo(String apkCheckUrl, String apkPath) {
    boolean flag = false; // Use the flag to indicate the result.
    FileOperation fileOperation = new FileOperation(); 
    
    // The application name and the version_name is optional.
//    String name; // To store the name of the application.
//    String version_name; // To store the version name of the application.
    
    String md5; // To store the md5 checksum of the application.
    String sha1; // To store the sha1 checksum of the application.
    
    // Get the md5 and sha1 checksum of the application file.
    md5 = fileOperation.fileToMD5(apkPath);
    sha1 = fileOperation.fileToSHA1(apkPath);
    
    HttpPost httpRequest =new HttpPost(apkCheckUrl); // Construct a new HttpPost instance according to the uri
    
    // use name-value pair to store the parameters to pass
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
//    params.add(new BasicNameValuePair("name", name)); // Add the name-value pair of the apk file.
    params.add(new BasicNameValuePair("md5", md5)); // Add the name-value of the md5 checksum of the apk file.
    params.add(new BasicNameValuePair("sha1", sha1)); // Add the name-value of the sha1 checksum of the apk file.
    
    logUtils.d(TAG, "params to send:" + params.toString());  // System out the params.
    
    try{
      
      // Encode the entity with utf8, and send the entity to the request
      httpRequest.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8)); 
      
    } catch (UnsupportedEncodingException e){
      e.printStackTrace();
    }
    try{
      // Execute an HTTP request and ge the result
      HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); // execute the http request
      
      // Response status is ok
      if(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK){  
      
        // Get the response string and parse it
        HttpEntity entity = httpResponse.getEntity(); // Obtain the HTTP response entity
        if (entity != null) { // The entity obtained is not null
          String info = EntityUtils.toString(entity); // Convert the entity to string
          
          logUtils.d(TAG, info); // log out the returned info
          
          JSONObject jsonObject=null;
          
          jsonObject = new JSONObject(info); // Construct an JsonObject instance from the name-value Json string
          String return_flag = jsonObject.getString("flag"); // Get the value mapped by name:flag
          
          // Judge whether the validation if succeeded according to the flag
          if(return_flag.equals("true")) { // If the flag is true, put the encrypt_level and encrypt_key to the resultHashMap.
            flag = true;
          } else { // The flag is false.
            flag = false;
          }
        }
      }
    } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      flag = false;
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      flag = false;
    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      flag = false;
    }
    return flag;
  }
}




Java Source Code List

com.twlkyao.androidcloud.ApkValidate.java
com.twlkyao.androidcloud.ContactsActivity.java
com.twlkyao.androidcloud.FileListAdapter.java
com.twlkyao.androidcloud.KuaipanDiskActivity.java
com.twlkyao.androidcloud.LoginActivity.java
com.twlkyao.androidcloud.MainActivity.java
com.twlkyao.androidcloud.MessageActivity.java
com.twlkyao.androidcloud.ObserverService.java
com.twlkyao.androidcloud.RegisterActivity.java
com.twlkyao.androidcloud.SetEncryptLevelActivity.java
com.twlkyao.androidcloud.StartUpReceiver.java
com.twlkyao.dao.DaoMaster.java
com.twlkyao.dao.DaoSession.java
com.twlkyao.dao.FileInfoDao.java
com.twlkyao.dao.FileInfo.java
com.twlkyao.kuaipan.DownloadTask.java
com.twlkyao.kuaipan.MkdirTask.java
com.twlkyao.kuaipan.RequestBase.java
com.twlkyao.kuaipan.ResultBase.java
com.twlkyao.kuaipan.TransportListener.java
com.twlkyao.kuaipan.UploadTask.java
com.twlkyao.utils.ApkOperation.java
com.twlkyao.utils.ConstantVariables.java
com.twlkyao.utils.ExportSms.java
com.twlkyao.utils.FileDEncryption.java
com.twlkyao.utils.FileOperation.java
com.twlkyao.utils.ImportSms.java
com.twlkyao.utils.LogUtils.java
com.twlkyao.utils.SmsField.java
com.twlkyao.utils.SmsItem.java
com.twlkyao.utils.StringSplice.java