package com.ysh.wpc.appupdate.download;
|
|
import java.io.File;
|
import java.io.FileNotFoundException;
|
import java.net.URLDecoder;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.Map;
|
import java.util.Set;
|
import java.util.TreeSet;
|
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
import android.content.ComponentName;
|
import android.content.Context;
|
import android.content.Intent;
|
import android.content.pm.ApplicationInfo;
|
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
|
import com.loopj.android.http.AsyncHttpClient;
|
import com.loopj.android.http.JsonHttpResponseHandler;
|
import com.loopj.android.http.RequestParams;
|
|
public class ApkUtil {
|
public static void openApk(Context context, String packageName,
|
String mainActivity) {
|
try {
|
Intent intent = new Intent();
|
ComponentName cmp = new ComponentName(packageName, mainActivity);
|
intent.setAction(Intent.ACTION_MAIN);
|
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.setComponent(cmp);
|
|
context.startActivity(intent);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
// 检查某个应用是否安装
|
public static boolean checkAPP(Context context, String packageName) {
|
if (packageName == null || "".equals(packageName))
|
return false;
|
try {
|
ApplicationInfo info = context.getPackageManager()
|
.getApplicationInfo(packageName,
|
PackageManager.GET_UNINSTALLED_PACKAGES);
|
return true;
|
} catch (NameNotFoundException e) {
|
return false;
|
}
|
}
|
|
// public static void OpenListeners(int id, String type) {
|
// final String mType = type;
|
// final int mId = id;
|
// Map<String, String> params = new HashMap<String, String>();
|
// params.put("Method", "setMoney");
|
// // params.put("Uid", AppContext.userInfo.getId() + "");
|
// params.put("Id", id + "");
|
// params.put("Type", type);
|
// // RandomCode = AppContext.userInfo.getRandomCode();
|
// params.put("RCode", RandomCode);
|
// params.put("Platform", platform);
|
// post("http://123.57.155.55:8080/YouHuiZhuan/API/money", params, null,
|
// new JsonHttpResponseHandler() {
|
//
|
// @Override
|
// public void onStart() {
|
// super.onStart();
|
// }
|
//
|
// @Override
|
// public void onFinish() {
|
// super.onFinish();
|
// }
|
//
|
// @Override
|
// public void onSuccess(int statusCode, Header[] headers,
|
// JSONObject response) {
|
// // TODO Auto-generated method stub
|
// super.onSuccess(statusCode, headers, response);
|
// Log.i("tasklist", response.toString());
|
// if (mType.equalsIgnoreCase("1")) {
|
// // AppContext.startRecord(mId, 3 + "");
|
// }
|
// }
|
//
|
// @Override
|
// public void onFailure(int statusCode, Header[] headers,
|
// Throwable throwable, JSONArray errorResponse) {
|
// super.onFailure(statusCode, headers, throwable,
|
// errorResponse);
|
// // UIUtils.showToast(context, "请求服务器失败");
|
// }
|
// });
|
// }
|
|
public static String RandomCode;
|
final static String platform = "Android";
|
private static AsyncHttpClient client = new AsyncHttpClient();
|
|
// public static void money(Map<String, String> params,
|
// JsonHttpResponseHandler handler) {
|
// if (StringUtils.isNullOrEmpty(RandomCode)
|
// && AppContext.userInfo != null) {
|
// RandomCode = AppContext.userInfo.getRandomCode();
|
// }
|
// RandomCode = AppContext.userInfo.getRandomCode();
|
// params.put("RCode", RandomCode);
|
// params.put("Platform", platform);
|
// post("http://123.57.155.55:8080/YouHuiZhuan/API/money", params, null,
|
// handler);
|
// }
|
|
public static void post(String url, Map<String, String> map,
|
HashMap<String, File> fileMap, JsonHttpResponseHandler handler) {
|
RequestParams params = new RequestParams();
|
TreeSet<String> treeSet = new TreeSet<String>();
|
Set<String> set = map.keySet();
|
Iterator<String> it = set.iterator();
|
String sign = "";
|
String org = "";
|
JSONObject object = new JSONObject();
|
while (it.hasNext()) {
|
String key = it.next();
|
treeSet.add(key);
|
}
|
it = treeSet.iterator();
|
while (it.hasNext()) {
|
String key = it.next();
|
try {
|
object.put(key, map.get(key));
|
} catch (JSONException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
// if (!StringUtils.isNullOrEmpty(map.get(key)))
|
// org += map.get(key) + "---";
|
}
|
|
// sign = StringUtils.MD5(org + "youHUIzhuan2015");
|
try {
|
String iSign = URLDecoder.decode(sign, "UTF-8");
|
object.put("Sign", iSign);
|
} catch (Exception e2) {
|
// TODO Auto-generated catch block
|
e2.printStackTrace();
|
}
|
params.put("Data", object.toString());
|
if (fileMap != null) {
|
Set<String> fileSet = fileMap.keySet();
|
it = fileSet.iterator();
|
|
while (it.hasNext()) {
|
String key = it.next();
|
try {
|
params.put(key, fileMap.get(key));
|
} catch (FileNotFoundException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
}
|
client.post(url, params, handler);
|
}
|
}
|