How do I obtain crash-data from my Android application?

前端 未结 30 2515
庸人自扰
庸人自扰 2020-11-22 01:10

How can I get crash data (stack traces at least) from my Android application? At least when working on my own device being retrieved by cable, but ideally from any instance

相关标签:
30条回答
  • 2020-11-22 01:22

    You can also use a whole (simple) service for it rather than only library. Our company just released a service just for that: http://apphance.com.

    It has a simple .jar library (for Android) that you add and integrate in 5 minutes and then the library gathers not only crash information but also logs from running application, as well as it lets your testers report problems straight from device - including the whole context (device rotation, whether it is connected to a wifi or not and more). You can look at the logs using a very nice and useful web panel, where you can track sessions with your application, crashes, logs, statistics and more. The service is in closed beta test phase now, but you can request access and we give it to you very quickly.

    Disclaimer: I am CTO of Polidea, and co-creator of the service.

    0 讨论(0)
  • 2020-11-22 01:22

    There is this android library called Sherlock. It gives you the full report of crash along with device and application information. Whenever a crash occurs, it displays a notification in the notification bar and on clicking of the notification, it opens the crash details. You can also share crash details with others via email or other sharing options.

    Installation

    android {
        dataBinding {
          enabled = true
        }
    }
    
    compile('com.github.ajitsing:sherlock:1.0.0@aar') {
        transitive = true
    }
    

    Demo

    0 讨论(0)
  • 2020-11-22 01:22

    Late to the party, I support and believe ACRA is the best option among all. Its easy to setup and configure. I have created a detailed guide with inputs from all over to fetch the crash report using ACRA and mail the same to my email address using MandrillAp.

    Link to post: https://androidician.wordpress.com/2015/03/29/sending-crash-reports-with-acra-over-email-using-mandrill/

    Link to sample project on github: https://github.com/ayushhgoyal/AcraSample

    0 讨论(0)
  • 2020-11-22 01:22

    I'm one of the founders of Bugsnag which we designed for exactly this purpose. Bugsnag automatically captures unhandled exceptions in Android apps and sends them to our dashboard, where you can prioritize fixes and dive into diagnostic information.

    Here are some important things to consider when selecting or building a crash reporting system, along with some code snippets:

    • Detects unhandled exceptions automatically (example code)
    • Collects diagnostic data such as memory usage, device info, etc (example code)
    • Effectively groups crashes together by root cause
    • Allows you to track actions the user took before each crash to help reproduce (example code)

    If you want to see some best practices around crash handling/reporting on Android you can check out the full source code for Bugsnag's crash reporting library which is fully open source, feel free to tear this apart and use it in your own applications!

    0 讨论(0)
  • 2020-11-22 01:23

    Thanks resources present in Stackoverflow in helping me to find this answer.

    You can find your remotely Android crash reports directly into your email. remmember you have to put your email inside CustomExceptionHandler class.

    public static String sendErrorLogsTo = "tushar.pandey@virtualxcellence.com" ;
    

    Steps required :

    1st) in onCreate of your activity use this section of your code.

        if(!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler)) {
            Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler(this));
        }   
    

    2nd) use this overridden version of CustomExceptionHandler class of ( rrainn ), according to my phpscript.

    package com.vxmobilecomm.activity;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.io.StringWriter;
    import java.io.Writer;
    import java.lang.Thread.UncaughtExceptionHandler;
    import java.util.ArrayList;
    import java.util.List;
    
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.entity.BufferedHttpEntity;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.message.BasicNameValuePair;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.pm.ApplicationInfo;
    import android.content.pm.PackageManager;
    import android.content.pm.PackageManager.NameNotFoundException;
    import android.os.AsyncTask;
    import android.util.Log;
    
    public class CustomExceptionHandler implements UncaughtExceptionHandler {
    
        private UncaughtExceptionHandler defaultUEH;
        public static String sendErrorLogsTo = "tushar.pandey@virtualxcellence.com" ;
    
        Activity activity;
    
        public CustomExceptionHandler(Activity activity) {
            this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
            this.activity = activity;
        }
    
        public void uncaughtException(Thread t, Throwable e) {
    
            final Writer result = new StringWriter();
            final PrintWriter printWriter = new PrintWriter(result);
            e.printStackTrace(printWriter);
            String stacktrace = result.toString();
            printWriter.close();
            String filename = "error" + System.nanoTime() + ".stacktrace";
    
            Log.e("Hi", "url != null");
            sendToServer(stacktrace, filename);
    
            StackTraceElement[] arr = e.getStackTrace();
            String report = e.toString() + "\n\n";
            report += "--------- Stack trace ---------\n\n";
            for (int i = 0; i < arr.length; i++) {
                report += "    " + arr[i].toString() + "\n";
            }
            report += "-------------------------------\n\n";
    
            report += "--------- Cause ---------\n\n";
            Throwable cause = e.getCause();
            if (cause != null) {
                report += cause.toString() + "\n\n";
                arr = cause.getStackTrace();
                for (int i = 0; i < arr.length; i++) {
                    report += "    " + arr[i].toString() + "\n";
                }
            }
            report += "-------------------------------\n\n";
    
            defaultUEH.uncaughtException(t, e);
        }
    
        private void sendToServer(String stacktrace, String filename) {
            AsyncTaskClass async = new AsyncTaskClass(stacktrace, filename,
                    getAppLable(activity));
            async.execute("");
        }
    
        public String getAppLable(Context pContext) {
            PackageManager lPackageManager = pContext.getPackageManager();
            ApplicationInfo lApplicationInfo = null;
            try {
                lApplicationInfo = lPackageManager.getApplicationInfo(
                        pContext.getApplicationInfo().packageName, 0);
            } catch (final NameNotFoundException e) {
            }
            return (String) (lApplicationInfo != null ? lPackageManager
                    .getApplicationLabel(lApplicationInfo) : "Unknown");
        }
    
        public class AsyncTaskClass extends AsyncTask<String, String, InputStream> {
            InputStream is = null;
            String stacktrace;
            final String filename;
            String applicationName;
    
            AsyncTaskClass(final String stacktrace, final String filename,
                    String applicationName) {
                this.applicationName = applicationName;
                this.stacktrace = stacktrace;
                this.filename = filename;
            }
    
            @Override
            protected InputStream doInBackground(String... params) 
            { 
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(
                        "http://suo-yang.com/books/sendErrorLog/sendErrorLogs.php?");
    
                Log.i("Error", stacktrace);
    
                try {
                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
                            6);
    
                    nameValuePairs.add(new BasicNameValuePair("data", stacktrace));
                    nameValuePairs.add(new BasicNameValuePair("to",sendErrorLogsTo));
                    nameValuePairs.add(new BasicNameValuePair("subject",applicationName));
    
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    
                    HttpResponse response = httpclient.execute(httppost);
    
                    HttpEntity entity1 = response.getEntity();
    
                    BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(
                            entity1);
    
                    is = bufHttpEntity.getContent();
    
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
                return is;
            }
    
            @Override
            protected void onPostExecute(InputStream result) {
                super.onPostExecute(result);
    
                Log.e("Stream Data", getStringFromInputStream(is));
            }
        }
    
        // convert InputStream to String
        private static String getStringFromInputStream(InputStream is) {
    
            BufferedReader br = null;
            StringBuilder sb = new StringBuilder();
    
            String line;
            try {
    
                br = new BufferedReader(new InputStreamReader(is));
                while ((line = br.readLine()) != null) {
                    sb.append(line);
                }
    
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (br != null) {
                    try {
                        br.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
    
            return sb.toString();
    
        }
    }
    
    0 讨论(0)
  • 2020-11-22 01:24

    I made my own version here : http://androidblogger.blogspot.com/2009/12/how-to-improve-your-application-crash.html

    It's basically the same thing, but I'm using a mail rather than a http connexion to send the report, and, more important, I added some informations like application version, OS version, Phone model, or avalaible memory to my report...

    0 讨论(0)
提交回复
热议问题