How to send app crash reports in Android
xCode:
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
/**
* Created by amit on 22/4/16.
*/
public class BaseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
handleUncaughtException(thread, ex);
}
});
}
public void handleUncaughtException (Thread thread, Throwable e)
{
String stackTrace = Log.getStackTraceString(e);
String message = e.getMessage();
Intent intent = new Intent (Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra (Intent.EXTRA_EMAIL, new String[] {"youremail@gmail.com"});
intent.putExtra (Intent.EXTRA_SUBJECT, "MyApp Crash log file");
intent.putExtra (Intent.EXTRA_TEXT, stackTrace);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// required when starting from Application
startActivity(intent);
}
}
In your AndroidManifest.xml specify the name for your application tag to be the name of your Class file.
<application
android:name=".TestApplication"
Whenever your application crashes, it will get caught in your custom Application class, and then it will call the default mailing application in the device by setting up a Mail Intent. Everything in the mail will already be filled – the user just has to click on Send. Or he can even copy the mail content and save it somewhere.
How to send app crash reports in Android
Reviewed by Anonymous
on
August 10, 2017
Rating:
No comments: