我是一名安卓开发者,我为客户开发应用程序。但是,在客户端设备中,通常会发生一些应用程序崩溃问题。但这并没有发生在我的设备中。但是我无法联系到我的客户,所以,这里有一个问题:~~~~ 有没有任何插件或工具可以实现到我的android应用程序中,所以当应用程序在我的客户端设备中崩溃时,崩溃日志将发送到我的电子邮件或我可以检查它的地方,所以我可以调试它。请指教,谢谢
问问题
88 次
3 回答
1
转到https://play.google.com/apps/publish/并发布您的应用。当用户安装您的应用程序并崩溃时,它会通知 Google,当您登录此控制面板时,您将能够在“报告”选项卡下,然后在“崩溃和 ANRS”下找到此类报告。
于 2015-07-15T04:15:39.627 回答
0
我认为您应该扩展 Application 类,并使用稳定的代码(独立于 android 版本)重新定义异常句柄。
代码示例:
你的应用程序.java
public class YourApplication extends Application {
@Override
public void onCreate() {
Thread.setDefaultUncaughtExceptionHandler(ExceptionHandler.inContext(getApplicationContext()));
super.onCreate();
}}
异常处理程序.java
final public class ExceptionHandler implements Thread.UncaughtExceptionHandler{
private final DateFormat formatter = new SimpleDateFormat("dd.MM.yy HH:mm");
private final DateFormat fileFormatter = new SimpleDateFormat("dd-MM-yy");
private String versionName = "0";
private int versionCode = 0;
private final String stacktraceDir;
private final Thread.UncaughtExceptionHandler previousHandler;
private ExceptionHandler(Context context, boolean chained) {
PackageManager mPackManager = context.getPackageManager();
PackageInfo mPackInfo;
try {
mPackInfo = mPackManager.getPackageInfo(context.getPackageName(), 0);
versionName = mPackInfo.versionName;
versionCode = mPackInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
// ignore
}
if(chained)
previousHandler = Thread.getDefaultUncaughtExceptionHandler();
else
previousHandler = null;
stacktraceDir = String.format("/Android/data/%s/files/", context.getPackageName());
}
static ExceptionHandler inContext(Context context) {
return new ExceptionHandler(context, true);
}
static ExceptionHandler reportOnlyHandler(Context context) {
return new ExceptionHandler(context, false);
}
@Override
public void uncaughtException(Thread thread, Throwable exception) {
final String state = Environment.getExternalStorageState();
final Date dumpDate = new Date(System.currentTimeMillis());
if (Environment.MEDIA_MOUNTED.equals(state)) {
StringBuilder reportBuilder = new StringBuilder();
reportBuilder
.append("\n\n\n")
.append(formatter.format(dumpDate)).append("\n")
.append(String.format("Version: %s (%d)\n", versionName, versionCode))
.append(thread.toString()).append("\n");
processThrowable(exception, reportBuilder);
File sd = Environment.getExternalStorageDirectory();
File stacktrace = new File(
sd.getPath() + stacktraceDir,
String.format(
"stacktrace-%s.txt",
fileFormatter.format(dumpDate)));
File dumpdir = stacktrace.getParentFile();
boolean dirReady = dumpdir.isDirectory() || dumpdir.mkdirs();
if (dirReady) {
FileWriter writer = null;
try {
writer = new FileWriter(stacktrace, true);
writer.write(reportBuilder.toString());
} catch (IOException e) {
// ignore
} finally {
try {
if (writer != null)
writer.close();
} catch (IOException e) {
// ignore
}
}
}
}
if(previousHandler != null)
previousHandler.uncaughtException(thread, exception);
}
private void processThrowable(Throwable exception, StringBuilder builder) {
if(exception == null)
return;
StackTraceElement[] stackTraceElements = exception.getStackTrace();
builder
.append("Exception: ").append(exception.getClass().getName()).append("\n")
.append("Message: ").append(exception.getMessage()).append("\nStacktrace:\n");
for(StackTraceElement element : stackTraceElements) {
builder.append("\t").append(element.toString()).append("\n");
}
processThrowable(exception.getCause(), builder);
}}
如果您的应用程序崩溃,您可以在 /sdcard/android/data/you.package.name/files/ 所有日志文件中找到带有 StackTrace 的日志。您还可以在每次应用启动时检查此文件夹中的新日志文件。如果您发现新文件,您可以将其发送到您的电子邮箱。
于 2015-07-15T04:37:48.160 回答
0
尝试看看 Crashlytics:http ://try.crashlytics.com/sdk-android/
于 2015-07-15T04:31:46.637 回答