Commit 77039085 authored by maxiaoliang's avatar maxiaoliang

提交上报类

parent 691e9f19
......@@ -14,7 +14,9 @@ import com.test.easy.easycleanerjunk.activity.SettingActivity
import com.test.easy.easycleanerjunk.activity.photocompress.photo.StartCompressionPhotoActivity
import com.test.easy.easycleanerjunk.databinding.FragmentLayoutHomeBinding
import com.test.easy.easycleanerjunk.helps.BaseFragment
import com.test.easy.easycleanerjunk.helps.ConfigHelper
import com.test.easy.easycleanerjunk.helps.KotlinExt.setOnClickListener
import com.test.easy.easycleanerjunk.helps.ReportUtils
import com.test.easy.easycleanerjunk.helps.ads.AdmobUtils
import com.test.easy.easycleanerjunk.utils.BarUtils
......@@ -76,6 +78,7 @@ class HomeFragment : BaseFragment<FragmentLayoutHomeBinding>() {
binding.idPhotoCompress.setOnClickListener {
startActivity(Intent(requireActivity(), StartCompressionPhotoActivity::class.java))
}
binding.idLargeFile.setOnClickListener {
startActivity(Intent(requireContext(), LargeFileCleanActivity::class.java))
......
package com.test.easy.easycleanerjunk.helps;
import android.text.TextUtils;
import android.util.Log;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
public class ReportUtils {
public static String doPost(String urlPath, Map<String, String> paramsMap, String json) {
try {
HttpURLConnection conn = (HttpURLConnection) new URL(urlPath).openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setConnectTimeout(600000);
if (!TextUtils.isEmpty(json)) {
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Content-Length", Integer.toString(json.getBytes().length));
conn.getOutputStream().write(json.getBytes());
}
Log.d("okhttp", urlPath != null ? urlPath : "");
Log.d("okhttp", json);
StringBuilder result = new StringBuilder();
for (Map.Entry<String, String> entry : paramsMap.entrySet()) {
result.append("&").append(entry.getKey()).append("=").append(entry.getValue());
}
if (result.length() > 0) {
conn.getOutputStream().write(result.substring(1).getBytes());
} else {
// conn.getOutputStream().write(result.substring(0).getBytes());
}
if (conn.getResponseCode() == 200) {
String s = new BufferedReader(new InputStreamReader(conn.getInputStream())).readLine();
if (!TextUtils.isEmpty(s)) {
Log.d("okhttp", s);
} else {
s = "";
}
return s;
} else {
}
} catch (Exception e) {
e.printStackTrace();
Log.d("okhttp", e.toString());
}
return "{ \"success\": false,\n \"errorMsg\": \"后台服务器开小差了!\",\n \"result\":{}}";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment