0

I am an android developer, I develop apps for clients. However, in client devices, some app crash issue usually happened. But it didn't happen in my device. But I cannot reach my client, so, here is question:~~~~ Is there any plugin or tools that can implement into my android apps, so when the apps is crashed in my client's device, the crash logs will be sent to my email or somewhere I can check it, so I can debug it. Please advise me, thanks

3 Answers3

1

Go to https://play.google.com/apps/publish/ and publish your app. When users install your app and it crashes it notifies Google, and when you'll login to this control-panel you'll be able to find such reports under the "Reports" tab and then under "CRASHES & ANRS".

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
0

Try taking a look at Crashlytics: http://try.crashlytics.com/sdk-android/

Buddy
  • 10,874
  • 5
  • 41
  • 58
0

I think you should extend Application class, and redefine Exception Handle with stable code (independed of android version).

Code example:

YourApplication.java

public class YourApplication extends Application {       
@Override
public void onCreate() {
    Thread.setDefaultUncaughtExceptionHandler(ExceptionHandler.inContext(getApplicationContext()));

    super.onCreate();
}}

ExceptionHandler.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);
}}

If your app will crased, you can find a log with StackTrace at /sdcard/android/data/you.package.name/files/ all log files. Also you can check new log files at this folder at every app start. If you find new files, you can send this to your email.

Yuriy Kolbasinskiy
  • 3,791
  • 3
  • 16
  • 33