新增全量日志采集系统
This commit is contained in:
parent
042f53e134
commit
834170e272
@ -1,14 +1,19 @@
|
||||
package com.shayu.phonelive.utils;
|
||||
|
||||
import static java.text.DateFormat.DEFAULT;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.yunbao.common.utils.FileUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URLEncoder;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LogUtils {
|
||||
public static void start(Context context) {
|
||||
@ -31,18 +36,26 @@ public class LogUtils {
|
||||
};
|
||||
|
||||
Process process = Runtime.getRuntime().exec(exec);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()), 1024);
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
File saveFile = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath());
|
||||
PrintWriter writer = null;
|
||||
String today ="[PDLIVE]"+CommonAppConfig.getInstance().getUid()+"_"+ SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date());
|
||||
File dir = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator);
|
||||
if (dir.listFiles() != null) {
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.getName().endsWith(today+".log") && !file.getName().endsWith("error.log")) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
File saveFile = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".log");
|
||||
FileOutputStream os = new FileOutputStream(saveFile);
|
||||
writer = new PrintWriter(os);
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
builder.append(line).append("\n");
|
||||
if (builder.length() > 65500) {
|
||||
FileUtil.saveAddStringToFile(saveFile, builder.toString(), "logcat.log");
|
||||
builder.setLength(0);
|
||||
writer.append(line).write("\n");
|
||||
}
|
||||
}
|
||||
|
||||
writer.flush();
|
||||
writer.close();
|
||||
exec = new String[]{
|
||||
"logcat",
|
||||
"-c"
|
||||
@ -52,10 +65,10 @@ public class LogUtils {
|
||||
start(context);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ToastUtil.show("");
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,22 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import static androidx.core.content.PermissionChecker.PERMISSION_GRANTED;
|
||||
import static java.text.DateFormat.DEFAULT;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.core.content.PermissionChecker;
|
||||
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.StringCallback;
|
||||
import com.lzy.okgo.model.Progress;
|
||||
@ -16,6 +29,9 @@ import com.yunbao.common.CommonAppConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -119,4 +135,30 @@ public class LogUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static void shareFile(Context context) {
|
||||
if(PermissionChecker.checkCallingOrSelfPermission(context,"android.permission.WRITE_EXTERNAL_STORAGE")!= PERMISSION_GRANTED){
|
||||
ActivityCompat.requestPermissions((Activity) context,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},100);
|
||||
return;
|
||||
}
|
||||
String today ="[PDLIVE]"+CommonAppConfig.getInstance().getUid()+"_"+ SimpleDateFormat.getDateInstance(DEFAULT, Locale.CHINA).format(new Date());
|
||||
File file = new File(context.getDir("files", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + today + ".log");
|
||||
file.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+file.getName()));
|
||||
if (file.exists()) {
|
||||
Intent share = new Intent(Intent.ACTION_SEND);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file);
|
||||
share.putExtra(Intent.EXTRA_STREAM, contentUri);
|
||||
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
} else {
|
||||
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
|
||||
}
|
||||
share.setType("application/vnd.ms-excel");
|
||||
share.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
context.startActivity(Intent.createChooser(share, "分享文件"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1062,7 +1062,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
private String TAG="多人PK";
|
||||
|
||||
private String TAG = "多人PK";
|
||||
|
||||
/**
|
||||
* 退出多人PK
|
||||
*/
|
||||
@ -1186,12 +1188,19 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
|
||||
@Override
|
||||
public void onSuccess(int code, String msgs, String[] info) {
|
||||
if (code == 0) {
|
||||
Log.i("多人PK","1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info)+" mApplyUid = "+mApplyUid);
|
||||
if (info.length == 0) {
|
||||
Log.i("多人PK", "1code = " + code + ", msgs = " + msgs + ", info = " + Arrays.deepToString(info) + " mApplyUid = " + mApplyUid);
|
||||
HttpClient.getInstance().get("live.getdrnum", "live.getdrnum")
|
||||
.execute(new HttpCallback() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
Log.i(TAG, "code = " + code + ", msg = " + msg + ", info = " + Arrays.deepToString(info));
|
||||
boolean agree=true;
|
||||
if (code != 0) {
|
||||
ToastUtil.show("多人PK次数已用完");
|
||||
return;
|
||||
agree=false;
|
||||
}
|
||||
rtcRoom.getLocalUser().responseJoinOtherRoom(mApplyUid, mApplyUid, true, true, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() {
|
||||
rtcRoom.getLocalUser().responseJoinOtherRoom(mApplyUid, mApplyUid, agree, true, SOCKET_LIVE_DRPK, new IRCRTCResultCallback() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
HttpClient.getInstance().get("live.joinDRPKroom", "live.joinDRPKroom")
|
||||
@ -1232,7 +1241,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
|
||||
Log.e("ry", "发送失敗");
|
||||
}
|
||||
});
|
||||
|
||||
if(info.length==0){
|
||||
return;
|
||||
}
|
||||
JSONObject obj = JSONObject.parseObject(info[0]);
|
||||
JSONArray users = obj.getJSONArray("userlist");
|
||||
|
||||
@ -1281,6 +1292,9 @@ public class LiveRyLinkMicPkPresenter implements View.OnClickListener {
|
||||
ToastUtil.show("接受失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.yunbao.common.Constants;
|
||||
import com.yunbao.common.interfaces.OnItemClickListener;
|
||||
import com.yunbao.common.utils.DeviceUtils;
|
||||
import com.yunbao.common.utils.LogUtil;
|
||||
import com.yunbao.common.views.weight.ViewClicksAntiShake;
|
||||
import com.yunbao.main.BuildConfig;
|
||||
import com.yunbao.main.R;
|
||||
@ -50,6 +51,9 @@ public class SettingAdapter extends RecyclerView.Adapter {
|
||||
if (tag != null) {
|
||||
int position = (int) tag;
|
||||
SettingBean bean = mList.get(position);
|
||||
if(bean.getId()==19){
|
||||
LogUtil.shareFile(context);
|
||||
}
|
||||
if (mOnItemClickListener != null) {
|
||||
mOnItemClickListener.onItemClick(bean, position);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user