0

I am using crashlytics for my android project, my requirement is that upon an app crash, I want to my own custom feedback activity and I also want to log this as a fatal exception in crashlytics. I tried approaches in the accepted answer : Crashlytics Android SDK - custom UncaughtExceptionHandler , but asynchronous initialization did not succeed for me. So, I tried initializing synchronously, like:

Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
    @Override
    public void uncaughtException(Thread thread, Throwable ex) {

      // launch feed back activity
      Intent intent = new Intent();
      intent.setAction("com.project.SEND_LOG");
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivity(intent);


      defaultUncaughtExceptionHandler.uncaughtException(thread, ex);
    }
  });

But this does not launch the feedback activity (though the code for launching feedback activity is executed), instead it shows the default app crashing behaviour in android. Can someone please help me with this ?

Rahul Gurnani
  • 174
  • 1
  • 13
  • Have look [this](https://stackoverflow.com/a/19968400/5110595) – Hemant Parmar Oct 10 '18 at 06:59
  • Thanks for responding, but this doesn't report a fatal exception to crashlytics. I do something similar, but am not able to figure out yet how to log this as a fatal exception to crashlytics. – Rahul Gurnani Oct 10 '18 at 07:07

2 Answers2

3

Thanks. This is not officially supported by Crashlytics. If you do find a workaround we cannot ensure that it will continue to work over time with updates to our SDK.

Todd Burner
  • 2,202
  • 12
  • 15
  • Thanks for answering :). But, I need to log an exception, with a severity level other than non-fatal exception, just to segregate the exceptions in the question. Isn't any clean way to achieve this ? As far as I know, there just 2 categories of exception, fatal(upon crash) and non-fatal (Crashlytics.logException). I need a third one so as to get alarmed once such an incident happens as I get alarmed with fatal exceptions currently. – Rahul Gurnani Oct 12 '18 at 18:29
2

From the official code example https://fabric.io/kits/android/crashlytics/features :

Make sure the Fabric.with() line is after all other 3rd-party SDKs that set an UncaughtExceptionHandler

Add meta-data in your AndroidManifest

<meta-data
            android:name="firebase_crashlytics_collection_enabled"
            android:value="false" />

Install UncaughtExceptionHandlers first then start Fabric.

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set all your UncaughtExceptionHandlers
        Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
        // Start your Crashlytics manually
        Fabric.with(this, new Crashlytics());
        ...
    }
}

Then you can get the report from crashlytics and catch error in your own UncaughtExceptionHandler. It works on my API27 mobile with crashlytics:2.10.1

gevge
  • 399
  • 2
  • 6