Java Code Examples for com.google.firebase.crashlytics.FirebaseCrashlytics#getInstance()

The following examples show how to use com.google.firebase.crashlytics.FirebaseCrashlytics#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Firebase.java    From SAI with GNU General Public License v3.0 5 votes vote down vote up
public static void setDataCollectionEnabled(Context context, boolean enabled) {
    Context appContext = context.getApplicationContext();

    FirebaseApp.getInstance().setDataCollectionDefaultEnabled(enabled);
    FirebaseAnalytics.getInstance(appContext).setAnalyticsCollectionEnabled(enabled);

    FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
    crashlytics.deleteUnsentReports();
    crashlytics.setCrashlyticsCollectionEnabled(enabled);
    crashlytics.deleteUnsentReports();
}
 
Example 2
Source File: GndApplication.java    From ground-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void log(int priority, String tag, @NonNull String message, Throwable throwable) {
  if (priority == Log.VERBOSE || priority == Log.DEBUG || priority == Log.INFO) {
    return;
  }

  FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
  crashlytics.log(message);

  if (throwable != null && priority == Log.ERROR) {
    crashlytics.recordException(throwable);
  }
}
 
Example 3
Source File: MainActivity.java    From snippets-android with Apache License 2.0 5 votes vote down vote up
public void resetKey() {
    // [START crash_re_set_key]
    FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();

    crashlytics.setCustomKey("current_level", 3);
    crashlytics.setCustomKey("last_UI_action", "logged_in");
    // [END crash_re_set_key]
}
 
Example 4
Source File: CrashUtil.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
public static void init() {
    if (crashlyticsEnabled) {
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
        crashlytics.setCrashlyticsCollectionEnabled(true);
        crashlytics.setCustomKey(DEVICE_ID, ReportingUtils.getDeviceId());
    }
}
 
Example 5
Source File: CrashUtil.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
public static void registerAppData() {
    if (crashlyticsEnabled) {
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
        crashlytics.setCustomKey(DOMAIN, ReportingUtils.getDomain());
        crashlytics.setCustomKey(APP_VERSION, ReportingUtils.getAppVersion());
        crashlytics.setCustomKey(APP_NAME, ReportingUtils.getAppName());
    }
}
 
Example 6
Source File: Logs.java    From SAI with GNU General Public License v3.0 4 votes vote down vote up
public static void init(Context context) {
    sPrefsHelper = PreferencesHelper.getInstance(context.getApplicationContext());
    sCrashlytics = FirebaseCrashlytics.getInstance();
}
 
Example 7
Source File: MainActivity.java    From quickstart-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());

    mCrashlytics = FirebaseCrashlytics.getInstance();

    // Log the onCreate event, this will also be printed in logcat
    mCrashlytics.log("onCreate");

    // Add some custom values and identifiers to be included in crash reports
    mCrashlytics.setCustomKey("MeaningOfLife", 42);
    mCrashlytics.setCustomKey("LastUIAction", "Test value");
    mCrashlytics.setUserId("123456789");

    // Report a non-fatal exception, for demonstration purposes
    mCrashlytics.recordException(new Exception("Non-fatal exception: something went wrong!"));

    // Button that causes NullPointerException to be thrown.
    binding.crashButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Log that crash button was clicked.
            mCrashlytics.log("Crash button clicked.");

            // If catchCrashCheckBox is checked catch the exception and report it using
            // logException(), Otherwise throw the exception and let Crashlytics automatically
            // report the crash.
            if (binding.catchCrashCheckBox.isChecked()) {
                try {
                    throw new NullPointerException();
                } catch (NullPointerException ex) {
                    // [START crashlytics_log_and_report]
                    mCrashlytics.log("NPE caught!");
                    mCrashlytics.recordException(ex);
                    // [END crashlytics_log_and_report]
                }
            } else {
                throw new NullPointerException();
            }
        }
    });

    // Log that the Activity was created.
    // [START crashlytics_log_event]
    mCrashlytics.log("Activity created");
    // [END crashlytics_log_event]
}
 
Example 8
Source File: ZephyrApplication.java    From zephyr with MIT License 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    sInstance = this;

    sApplicationComponent = DaggerApplicationComponent.builder()
            .applicationModule(new ApplicationModule(this))
            .build();

    sApplicationComponent.inject(ZephyrApplication.this);
    sApplicationComponent.init();

    registerActivityLifecycleCallbacks(new ZephyrLifecycleLogger());
    ProcessLifecycleOwner.get().getLifecycle().addObserver(this);

    EventBus.builder().logNoSubscriberMessages(false).installDefaultEventBus();

    if (configManager.isFirebaseEnabled()) {
        FirebaseApp.initializeApp(this);
    } else {
        logger.log(LogLevel.WARNING, LOG_TAG, "Firebase disabled, some features will be limited or disabled.");
    }

    if (configManager.isFirebasePerformanceMonitoringEnabled()) {
        FirebasePerformance.getInstance().setPerformanceCollectionEnabled(true);
    }

    FirebaseCrashlytics firebaseCrashlytics = FirebaseCrashlytics.getInstance();
    if (privacyManager.isCrashReportingEnabled()) {
        firebaseCrashlytics.setCrashlyticsCollectionEnabled(true);
        firebaseCrashlytics.setUserId(privacyManager.getUuid());
        sCrashReportingInitialized = true;
    } else {
        firebaseCrashlytics.setCrashlyticsCollectionEnabled(false);
        logger.log(LogLevel.WARNING, LOG_TAG, "Crashlytics disabled.");
    }

    if (!BuildConfig.PROPS_SET) {
        logger.log(LogLevel.WARNING, LOG_TAG, "Secret properties not set! Some features will be limited or disabled.");
    }

    if (flipperManager.isInitialized()) {
        logger.log(LogLevel.INFO, LOG_TAG, "Flipper initialized.");
    }

    logger.log(LogLevel.DEBUG, LOG_TAG, "Zephyr %s (%s - %s) started.", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE, BuildConfig.GIT_HASH);

    themeManager.setDefaultNightMode();

    sApplicationComponent.notificationsManager().createNotificationChannels();

    workManager.initWork();

    verifyConnectionStatus();

    // Check for updates from AppCenter if beta.
    // TODO: Refactor to be generic and to support other tracks.
    if (BuildConfig.PROPS_SET && configManager.isBeta()) {
        AppCenter.start(this, BuildConfig.APP_CENTER_SECRET, Distribute.class);
    } else if (!BuildConfig.PROPS_SET && configManager.isBeta()) {
        logger.log(LogLevel.WARNING, LOG_TAG, "AppCenter update check disabled -- APP_CENTER_SECRET not set!");
    }

    if (configManager.isDiscoveryEnabled()) {
        logger.log(LogLevel.INFO, LOG_TAG, "Starting DiscoveryManager.");
        discoveryManager.start();
    }

    // Track version code
    preferenceManager.getInt(PreferenceKeys.PREF_LAST_KNOWN_APP_VERSION, BuildConfigUtils.getVersionCode());
}
 
Example 9
Source File: MainActivity.java    From snippets-android with Apache License 2.0 3 votes vote down vote up
public void setKeysBasic() {
    // [START crash_set_keys_basic]
    FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();

    crashlytics.setCustomKey("my_string_key", "foo" /* string value */);

    crashlytics.setCustomKey("my_bool_key", true /* boolean value */);

    crashlytics.setCustomKey("my_double_key", 1.0 /* double value */);

    crashlytics.setCustomKey("my_float_key", 1.0f /* float value */);

    crashlytics.setCustomKey("my_int_key", 1 /* int value */);
    // [END crash_set_keys_basic]
}