mirror of
https://gitea.winboll.cc/Studio/WinBoLL.git
synced 2026-08-14 13:37:11 +08:00
恢复beta版异常调试邮件发送功能框架。
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Thu Jul 23 17:50:15 HKT 2026
|
||||
#Thu Jul 23 10:33:06 GMT 2026
|
||||
stageCount=4
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.21
|
||||
publishVersion=15.21.3
|
||||
buildCount=18
|
||||
buildCount=24
|
||||
baseBetaVersion=15.21.4
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package cc.winboll.studio.appbase;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import cc.winboll.studio.libappbase.CrashActivity;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.utils.APPMSGMailUtils;
|
||||
import cc.winboll.studio.libappbase.utils.CrashHandleNotifyUtils;
|
||||
import cc.winboll.studio.libappbase.utils.SMTPUtils;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
@@ -33,22 +31,32 @@ public class App extends GlobalApplication {
|
||||
public void onCreate() {
|
||||
try {
|
||||
super.onCreate();
|
||||
|
||||
|
||||
// 初始化 Toast 工具类(传入应用全局上下文,确保 Toast 可在任意地方调用)
|
||||
ToastUtils.init(getApplicationContext());
|
||||
|
||||
// 调试异常捕获
|
||||
final String errorMsg = "初始化异常捕获调试信息,这个是调试异常捕获的测试数据。";
|
||||
LogUtils.e(TAG, errorMsg);
|
||||
throw new IllegalArgumentException(errorMsg);
|
||||
|
||||
} catch (Throwable e) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
pw.close();
|
||||
String stackTraceStr = sw.toString();
|
||||
|
||||
// 发送异常信息邮箱。
|
||||
sendExceptionMail(stackTraceStr);
|
||||
|
||||
// 前台通知栏提醒。
|
||||
CrashHandleNotifyUtils.handleUncaughtException(
|
||||
this,
|
||||
getPackageName(),
|
||||
stackTraceStr,
|
||||
CrashActivity.class
|
||||
);
|
||||
sendExceptionMail(stackTraceStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,50 +66,7 @@ public class App extends GlobalApplication {
|
||||
* @param stackTraceStr 异常堆栈信息
|
||||
*/
|
||||
private void sendExceptionMail(final String stackTraceStr) {
|
||||
SharedPreferences sp = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
|
||||
final String host = sp.getString("smtp_server", "");
|
||||
final String portStr = sp.getString("smtp_port", "");
|
||||
final String sender = sp.getString("sender_email", "");
|
||||
final String auth = sp.getString("auth_code", "");
|
||||
final String recipient = sp.getString("recipient_email", "");
|
||||
|
||||
if (host.isEmpty() || portStr.isEmpty() || sender.isEmpty()
|
||||
|| auth.isEmpty() || recipient.isEmpty()) {
|
||||
LogUtils.d(TAG, "sendExceptionMail skipped, SMTP config incomplete");
|
||||
return;
|
||||
}
|
||||
|
||||
final int port;
|
||||
try {
|
||||
port = Integer.parseInt(portStr);
|
||||
} catch (NumberFormatException e) {
|
||||
LogUtils.e(TAG, "sendExceptionMail failed, port format error: " + portStr);
|
||||
return;
|
||||
}
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String deviceInfo = "\n\n--- Device Info ---\n"
|
||||
+ "Package: " + getPackageName() + "\n"
|
||||
+ "Time: " + System.currentTimeMillis() + "\n";
|
||||
|
||||
boolean success = SMTPUtils.sendTextMail(
|
||||
recipient,
|
||||
"APPBase 异常报告",
|
||||
stackTraceStr + deviceInfo,
|
||||
sender,
|
||||
auth,
|
||||
host,
|
||||
port);
|
||||
|
||||
if (success) {
|
||||
LogUtils.d(TAG, "sendExceptionMail success");
|
||||
} else {
|
||||
LogUtils.e(TAG, "sendExceptionMail failed");
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
APPMSGMailUtils.sendMail();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@ import android.view.View;
|
||||
import android.widget.Toolbar;
|
||||
import cc.winboll.studio.appbase.R;
|
||||
import cc.winboll.studio.appbase.model.TestBean;
|
||||
import cc.winboll.studio.appbase.develop.APPExcetionMailSettingsActivity;
|
||||
import cc.winboll.studio.libappbase.LogActivity;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
@@ -49,6 +50,7 @@ public class MainActivity extends Activity {
|
||||
setActionBar(mToolbar); // 将 Toolbar 替代系统默认 ActionBar
|
||||
|
||||
initTestData();
|
||||
setupShortcuts();
|
||||
}
|
||||
|
||||
void initTestData() {
|
||||
@@ -64,6 +66,36 @@ public class MainActivity extends Activity {
|
||||
return "/BaseBaen/"+TestBean.class.getName()+".json";
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册桌面图标静态快捷方式
|
||||
* 长按桌面图标后显示快捷菜单,点击可直接打开异常邮件接收设置页面
|
||||
*/
|
||||
private void setupShortcuts() {
|
||||
if (!"cc.winboll.studio.appbase.beta".equals(getPackageName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
|
||||
if (shortcutManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, APPExcetionMailSettingsActivity.class);
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "exception_mail_settings")
|
||||
.setShortLabel("邮件设置")
|
||||
.setLongLabel("异常邮件接收设置")
|
||||
.setIcon(Icon.createWithResource(this, R.drawable.ic_winboll))
|
||||
.setIntent(intent)
|
||||
.build();
|
||||
|
||||
shortcutManager.setDynamicShortcuts(
|
||||
java.util.Arrays.asList(shortcut)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建菜单时回调(加载工具栏菜单)
|
||||
* 初始化 ActionBar 菜单,加载自定义菜单布局
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package cc.winboll.studio.appbase.develop;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import cc.winboll.studio.appbase.R;
|
||||
import cc.winboll.studio.libappbase.views.SMTPConfigView;
|
||||
|
||||
/**
|
||||
* @Author 豆包&BigPickle&MiMo&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/07/21 12:44
|
||||
* @Describe 应用异常信息邮件接收账号设置
|
||||
* 使用libaes的SMTPConfigView控件配置SMTP服务器参数
|
||||
*/
|
||||
public class APPExcetionMailSettingsActivity extends Activity {
|
||||
|
||||
public static final String TAG = "APPExcetionMailSettingsActivity";
|
||||
|
||||
private SMTPConfigView mSMTPConfigView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_appexcetionmailsettings);
|
||||
|
||||
mSMTPConfigView = (SMTPConfigView) findViewById(R.id.smtp_config_view);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
android:layout_height="match_parent"
|
||||
android:background="#FAFAFA">
|
||||
|
||||
<cc.winboll.studio.libaes.views.SMTPConfigView
|
||||
<cc.winboll.studio.libappbase.views.SMTPConfigView
|
||||
android:id="@+id/smtp_config_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Thu Jul 23 17:50:15 HKT 2026
|
||||
#Thu Jul 23 10:33:06 GMT 2026
|
||||
stageCount=4
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.21
|
||||
publishVersion=15.21.3
|
||||
buildCount=18
|
||||
buildCount=24
|
||||
baseBetaVersion=15.21.4
|
||||
|
||||
Reference in New Issue
Block a user