feat(appbase): 优化快捷方式配置与崩溃日志分享功能

1. 快捷方式改为静态XML配置(仅beta渠道)
   - 新增 res/xml/shortcuts.xml 定义静态快捷方式
   - AndroidManifest.xml 添加 meta-data 引用
   - MainActivity.setupShortcuts() 移除动态注册代码

2. 崩溃日志分享功能增强
   - CrashHandleNotifyUtils: 新增 appAPKName/emailTo 参数
   - ShareLogActivity: 添加邮件接收者(EXTRA_EMAIL)支持
   - 邮件标题格式: {应用名} - 崩溃日志
   - 邮件内容添加应用版本号和设备运行环境信息
   - 通知按钮名称改为: 发送日志给开发组

3. 调用方适配
   - App.java: 传入 APPBase 和 studio@winboll.cc
This commit is contained in:
7 changed files with 111 additions and 38 deletions
@@ -67,11 +67,15 @@ public class CrashHandleNotifyUtils {
* @param hostPackageName 宿主应用包名
* @param errorLog 崩溃日志内容
* @param reportCrashActivity 崩溃详情跳转Activity类
* @param appAPKName 应用APK名称(用于邮件标题)
* @param emailTo 邮件接收者地址
*/
public static void handleUncaughtException(final android.app.Application hostApp,
final String hostPackageName,
final String errorLog,
final Class<?> reportCrashActivity) {
final Class<?> reportCrashActivity,
final String appAPKName,
final String emailTo) {
LogUtils.d(TAG, "handleUncaughtException 进入方法");
if (hostApp == null || TextUtils.isEmpty(hostPackageName) || TextUtils.isEmpty(errorLog)) {
LogUtils.e(TAG, "handleUncaughtException 参数为空校验不通过");
@@ -87,7 +91,14 @@ public class CrashHandleNotifyUtils {
sCrashLogCacheFilePath = crashLogFilePath;
final Intent shareIntent = new Intent(hostApp, ShareLogActivity.class);
shareIntent.putExtra(ShareLogActivity.EXTRA_CRASH_LOG_FILEPATH, crashLogFilePath);
shareIntent.putExtra(ShareLogActivity.EXTRA_CRASH_LOG_SUBJECT, "崩溃日志");
String subject = "崩溃日志";
if (appAPKName != null && !appAPKName.isEmpty()) {
subject = appAPKName + " - 崩溃日志";
}
shareIntent.putExtra(ShareLogActivity.EXTRA_CRASH_LOG_SUBJECT, subject);
if (emailTo != null && !emailTo.isEmpty()) {
shareIntent.putExtra(ShareLogActivity.EXTRA_CRASH_LOG_EMAIL_TO, emailTo);
}
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final PendingIntent sharePendingIntent = createSharePendingIntent(hostApp, shareIntent);
sendCrashNotification(hostApp, hostPackageName, hostAppName, errorLog, reportCrashActivity, sharePendingIntent);
@@ -109,7 +120,21 @@ public class CrashHandleNotifyUtils {
LogUtils.w(TAG, "未携带宿主包名,默认使用应用自身包名");
}
final String errorLog = intent.getStringExtra(CrashHandler.EXTRA_CRASH_LOG);
handleUncaughtException(hostApp, hostPackageName, errorLog, reportCrashActivity);
handleUncaughtException(hostApp, hostPackageName, errorLog, reportCrashActivity, null, null);
}
/**
* 重载兼容方法:适配原有调用方式
* @param hostApp 宿主Application实例
* @param hostPackageName 宿主应用包名
* @param errorLog 崩溃日志内容
* @param reportCrashActivity 崩溃详情跳转Activity类
*/
public static void handleUncaughtException(final android.app.Application hostApp,
final String hostPackageName,
final String errorLog,
final Class<?> reportCrashActivity) {
handleUncaughtException(hostApp, hostPackageName, errorLog, reportCrashActivity, null, null);
}
/**
@@ -355,7 +380,7 @@ public class CrashHandleNotifyUtils {
.setWhen(System.currentTimeMillis())
.setPriority(Notification.PRIORITY_DEFAULT);
if (shareIntent != null) {
builder.addAction(android.R.drawable.ic_menu_send, "分享日志", shareIntent);
builder.addAction(android.R.drawable.ic_menu_send, "发送日志给开发组", shareIntent);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return builder.build();
@@ -2,6 +2,9 @@ package cc.winboll.studio.libappbase.utils;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
@@ -21,6 +24,7 @@ public class ShareLogActivity extends Activity {
public static final String TAG = "ShareLogActivity";
public static final String EXTRA_CRASH_LOG_FILEPATH = "crash_log_filepath";
public static final String EXTRA_CRASH_LOG_SUBJECT = "crash_log_subject";
public static final String EXTRA_CRASH_LOG_EMAIL_TO = "crash_log_email_to";
@Override
protected void onCreate(final Bundle savedInstanceState) {
@@ -43,10 +47,40 @@ public class ShareLogActivity extends Activity {
}
final String subject = intent.getStringExtra(EXTRA_CRASH_LOG_SUBJECT);
handleShareCrashLog(crashLogFilePath, subject);
final String emailTo = intent.getStringExtra(EXTRA_CRASH_LOG_EMAIL_TO);
handleShareCrashLog(crashLogFilePath, subject, emailTo);
}
private void handleShareCrashLog(final String crashLogFilePath, final String subject) {
private String getAppInfo() {
StringBuilder sb = new StringBuilder();
sb.append("========== 应用信息 ==========\n");
try {
PackageInfo pkgInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
sb.append("应用包名: ").append(getPackageName()).append("\n");
sb.append("版本名称: ").append(pkgInfo.versionName).append("\n");
sb.append("版本号: ").append(pkgInfo.versionCode).append("\n");
} catch (PackageManager.NameNotFoundException e) {
sb.append("应用包名: ").append(getPackageName()).append("\n");
sb.append("版本信息: 获取失败\n");
}
sb.append("\n");
return sb.toString();
}
private String getDeviceInfo() {
StringBuilder sb = new StringBuilder();
sb.append("========== 设备信息 ==========\n");
sb.append("设备制造商: ").append(Build.MANUFACTURER).append("\n");
sb.append("设备型号: ").append(Build.MODEL).append("\n");
sb.append("设备名称: ").append(Build.DEVICE).append("\n");
sb.append("Android版本: ").append(Build.VERSION.RELEASE).append("\n");
sb.append("Android API: ").append(Build.VERSION.SDK_INT).append("\n");
sb.append("系统指纹: ").append(Build.FINGERPRINT).append("\n");
sb.append("\n");
return sb.toString();
}
private void handleShareCrashLog(final String crashLogFilePath, final String subject, final String emailTo) {
Log.d(TAG, "handleShareCrashLog crashLogFilePath = " + crashLogFilePath);
final File crashLogFile = new File(crashLogFilePath);
@@ -67,16 +101,25 @@ public class ShareLogActivity extends Activity {
}
final String logContent = sb.toString();
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, logContent);
final StringBuilder emailContent = new StringBuilder();
emailContent.append(getAppInfo());
emailContent.append(getDeviceInfo());
emailContent.append("========== 崩溃日志 ==========\n");
emailContent.append(logContent);
final Intent shareIntent = new Intent(Intent.ACTION_SENDTO);
shareIntent.setData(android.net.Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_TEXT, emailContent.toString());
if (subject != null && !subject.isEmpty()) {
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
} else {
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "崩溃日志");
}
if (emailTo != null && !emailTo.isEmpty()) {
shareIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{emailTo});
}
startActivity(Intent.createChooser(shareIntent, "分享日志到"));
startActivity(Intent.createChooser(shareIntent, "发送日志到"));
Log.d(TAG, "handleShareCrashLog 分享成功");
} catch (Exception e) {
Log.e(TAG, "handleShareCrashLog 异常", e);