admin
2024-01-26 c2d382d99ca506932985d1843d4371d6ed0203ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.weikou.beibeivideo.util.downutil;
 
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 {
            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);
    }
}