com.google.firebase.crashlytics.FirebaseCrashlytics Java Examples

The following examples show how to use com.google.firebase.crashlytics.FirebaseCrashlytics. 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: LaunchActivity.java    From intra42 with Apache License 2.0 6 votes vote down vote up
public void onLoginClick(View view) {
    Analytics.signInAttempt();
    Uri loginUri = Uri.parse(ApiService.API_BASE_URL + "/oauth/authorize?client_id=" + Credential.UID + "&redirect_uri=" + Credential.API_OAUTH_REDIRECT + "&response_type=code&scope=" + Credential.SCOPE);

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setShowTitle(true);
    builder.setInstantAppsEnabled(true);

    Intent defaultBrowserIntent = new Intent(Intent.ACTION_VIEW);
    defaultBrowserIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    defaultBrowserIntent.setData(loginUri);
    PendingIntent defaultBrowserPendingIntent = PendingIntent.getActivity(this, 0, defaultBrowserIntent, 0);

    builder.addMenuItem(getString(R.string.login_custom_chrome_tabs_open_default_browser), defaultBrowserPendingIntent);
    CustomTabsIntent customTabsIntent = builder.build();
    customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try {
        customTabsIntent.launchUrl(this, loginUri);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        FirebaseCrashlytics.getInstance().recordException(e);
        Toast.makeText(app, R.string.login_error_web_browser_required, Toast.LENGTH_SHORT).show();
    }
}
 
Example #2
Source File: EventCollector.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
static public void logEvent(String event) {
	if (!mDisabled) {
		FirebaseCrashlytics.getInstance().log(event);

		Bundle params = new Bundle();
		mFirebaseAnalytics.logEvent(event, params);
	}
}
 
Example #3
Source File: Logger.java    From zephyr with MIT License 5 votes vote down vote up
private void logToCrashlytics(@NonNull LogEntry logEntry) {
    if (logEntry.getPriority() < Constants.MIN_LOG_LEVEL_CRASHLYTICS) {
        return;
    }

    FirebaseCrashlytics.getInstance().log(logEntry.toString());
}
 
Example #4
Source File: ClusterMapContributeEditActivity.java    From intra42 with Apache License 2.0 5 votes vote down vote up
void save() {
    app.firebaseRefClusterMapContribute.child(clusterSlug).runTransaction(new Transaction.Handler() {
        @NonNull
        @Override
        public Transaction.Result doTransaction(@NonNull MutableData mutableData) {
            Cluster clusterMutable = mutableData.getValue(Cluster.class);
            if (clusterMutable == null) {
                return Transaction.success(mutableData);
            }

            clusterMutable.width = cluster.width;
            clusterMutable.height = cluster.height;
            clusterMutable.map = cluster.map;

            Map<String, Object> export = clusterMutable.toMap();
            mutableData.setValue(export);
            return Transaction.success(mutableData);
        }

        @Override
        public void onComplete(DatabaseError databaseError, boolean b,
                               DataSnapshot dataSnapshot) {
            // Transaction completed
            if (databaseError != null)
                FirebaseCrashlytics.getInstance().log("postTransaction:onComplete:" + databaseError);
        }
    });
}
 
Example #5
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 #6
Source File: AppClass.java    From intra42 with Apache License 2.0 5 votes vote down vote up
public void logout() {
    me = null;
    ServiceGenerator.logout();
    SharedPreferences sharedPreferences = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.remove(API_ME_LOGIN);
    editor.apply();
    Token.removeToken(this);
    FirebaseCrashlytics.getInstance().setUserId("");
}
 
Example #7
Source File: AppClass.java    From intra42 with Apache License 2.0 5 votes vote down vote up
void initFirebase() {
    try {
        FirebaseDatabase database = FirebaseDatabase.getInstance();
        firebaseRefClusterMapContribute = database.getReference("cluster_map");
    } catch (IllegalStateException | NullPointerException e) {
        e.printStackTrace();
        FirebaseCrashlytics.getInstance().recordException(e);
    }
}
 
Example #8
Source File: MainActivity.java    From snippets-android with Apache License 2.0 5 votes vote down vote up
public void logCaughtEx() {
    // [START crash_log_caught_ex]
    try {
        methodThatThrows();
    } catch (Exception e) {
        FirebaseCrashlytics.getInstance().recordException(e);
        // handle your exception here
    }
    // [END crash_log_caught_ex]
}
 
Example #9
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 #10
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 #11
Source File: EventCollector.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
static public void logEvent(String event, double value) {
	if (!mDisabled) {
		FirebaseCrashlytics.getInstance().log(event);

		Bundle params = new Bundle();
		params.putDouble("dv", value);
		mFirebaseAnalytics.logEvent(event, params);
	}
}
 
Example #12
Source File: VinylCastApplicationBase.java    From vinyl-cast with MIT License 5 votes vote down vote up
@Override
protected void log(int priority, @Nullable String tag, @NotNull String message, @Nullable Throwable throwable) {
    if (priority >= Log.DEBUG) {
        FirebaseCrashlytics.getInstance().log(message);
        if (throwable != null) {
            FirebaseCrashlytics.getInstance().recordException(throwable);
        }
    } else {
        return;
    }
}
 
Example #13
Source File: VinylCastApplicationBase.java    From vinyl-cast with MIT License 5 votes vote down vote up
@Override
protected void log(int priority, @Nullable String tag, @NotNull String message, @Nullable Throwable throwable) {
    if (priority >= Log.DEBUG) {
        FirebaseCrashlytics.getInstance().log(message);
        if (throwable != null) {
            FirebaseCrashlytics.getInstance().recordException(throwable);
        }
    } else {
        return;
    }
}
 
Example #14
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 #15
Source File: EventCollector.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
static public void logEvent(String category, String event) {
	if (!mDisabled) {
		FirebaseCrashlytics.getInstance().log(category+":"+event);

		Bundle params = new Bundle();
		params.putString("event", event);
		mFirebaseAnalytics.logEvent(category, params);
	}
}
 
Example #16
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 #17
Source File: AnalyticsApplication.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
@Override
@CallSuper
public void onCreate() {
    super.onCreate();

    String uuid = Prefs.getString(CommonPK.ANALYTICS_USER_ID, null);
    if (uuid == null) {
        uuid = UUID.randomUUID().toString();
        Prefs.putString(CommonPK.ANALYTICS_USER_ID, uuid);
    }

    if (FossUtils.hasFirebaseCrashlytics()) {
        if (Prefs.getBoolean(CommonPK.CRASH_REPORT_ENABLED)) {
            FirebaseCrashlytics.getInstance().setUserId(uuid);
            CRASHLYTICS_ENABLED = true;
        } else {
            CRASHLYTICS_ENABLED = false;
        }
    } else {
        Prefs.putBoolean(CommonPK.CRASH_REPORT_ENABLED, false);
    }

    if (FossUtils.hasFirebaseAnalytics()) {
        ANALYTICS = FirebaseAnalytics.getInstance(this);
        if (Prefs.getBoolean(CommonPK.TRACKING_ENABLED)) {
            ANALYTICS.setUserId(uuid);
            ANALYTICS.setAnalyticsCollectionEnabled(true);
        } else {
            ANALYTICS.setAnalyticsCollectionEnabled(false);
            ANALYTICS = null;
        }
    } else {
        Prefs.putBoolean(CommonPK.TRACKING_ENABLED, false);
    }
}
 
Example #18
Source File: EventCollector.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
static public void logEvent(String category, String event, String label) {
	if (!mDisabled) {
		FirebaseCrashlytics.getInstance().log(category+":"+event+":"+label);

		Bundle params = new Bundle();
		params.putString("event", event);
		params.putString("label", label);
		mFirebaseAnalytics.logEvent(category, params);
	}
}
 
Example #19
Source File: EventCollector.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
static private void logException(Throwable e, int level) {
	if(!mDisabled) {
		StackTraceElement [] stackTraceElements = e.getStackTrace();
		e.setStackTrace(Arrays.copyOfRange(stackTraceElements,level,stackTraceElements.length));
		FirebaseCrashlytics.getInstance().recordException(e);

		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		PrintStream ps = new PrintStream(baos);
		e.printStackTrace(ps);
		ps.close();

		FirebaseCrashlytics.getInstance().log(Utils.EMPTY_STRING+System.currentTimeMillis()+":"+e.getMessage() + ":"+ baos.toString());
	}
}
 
Example #20
Source File: Tools.java    From intra42 with Apache License 2.0 4 votes vote down vote up
/**
 * Open url like "/stuff/file.txt"
 *
 * @param activity A Activity
 * @param url      the url
 */
public static void openAttachment(Activity activity, String url) {
    if (url != null) {

        if (!url.startsWith("http"))
            url = "https://cdn.intra.42.fr" + url;

        Uri uri = Uri.parse(url.replace("/uploads", ""));

        Intent intent = new Intent(Intent.ACTION_VIEW);
        // Check what kind of file you are trying to open, by comparing the url with extensions.
        // When the if condition is matched, plugin sets the correct intent (mime) type,
        // so Android knew what application to use to open the file
        if (url.contains(".doc") || url.contains(".docx")) {
            // Word document
            intent.setDataAndType(uri, "application/msword");
        } else if (url.contains(".pdf")) {
            // PDF file
            intent.setDataAndType(uri, "application/pdf");
        } else if (url.contains(".ppt") || url.contains(".pptx")) {
            // Powerpoint file
            intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
        } else if (url.contains(".xls") || url.contains(".xlsx")) {
            // Excel file
            intent.setDataAndType(uri, "application/vnd.ms-excel");
        } else if (url.contains(".zip") || url.contains(".rar")) {
            // WAV audio file
            intent.setDataAndType(uri, "application/x-wav");
        } else if (url.contains(".rtf")) {
            // RTF file
            intent.setDataAndType(uri, "application/rtf");
        } else if (url.contains(".wav") || url.contains(".mp3")) {
            // WAV audio file
            intent.setDataAndType(uri, "audio/x-wav");
        } else if (url.contains(".gif")) {
            // GIF file
            intent.setDataAndType(uri, "image/gif");
        } else if (url.contains(".jpg") || url.contains(".jpeg") || url.contains(".png")) {
            // JPG file
            intent.setDataAndType(uri, "image/jpeg");
        } else if (url.contains(".txt")) {
            // Text file
            intent.setDataAndType(uri, "text/plain");
        } else if (url.contains(".3gp") || url.contains(".mpg") || url.contains(".mpeg") || url.contains(".mpe") || url.contains(".mp4") || url.contains(".avi")) {
            // Video files
            intent.setDataAndType(uri, "video/*");
        } else {
            //if you want you can also define the intent type for any other file

            //additionally use else clause below, to manage other unknown extensions
            //in this case, Android will show all applications installed on the device
            //so you can choose which application to use intent.setDataAndType(uri, "*/*");
            intent.setDataAndType(uri, "text/plain");
        }

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            activity.startActivity(intent);
        } catch (android.content.ActivityNotFoundException ex) {
            FirebaseCrashlytics.getInstance().recordException(ex);
            if (url.contains(".3gp") || url.contains(".mpg") || url.contains(".mpeg") || url.contains(".mpe") || url.contains(".mp4") || url.contains(".avi"))
                Toast.makeText(activity, R.string.info_attachment_no_app_video, Toast.LENGTH_SHORT).show();
            else if (url.contains(".pdf"))
                Toast.makeText(activity, R.string.info_attachment_no_app_pdf, Toast.LENGTH_SHORT).show();
            else
                Toast.makeText(activity, R.string.info_attachment_no_app, Toast.LENGTH_SHORT).show();
        } catch (java.lang.SecurityException e) {
            FirebaseCrashlytics.getInstance().recordException(e);
            Toast.makeText(activity, R.string.info_attachment_no_app, Toast.LENGTH_SHORT).show();
        }
    }
}
 
Example #21
Source File: CrashUtil.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public static void log(String message) {
    if (crashlyticsEnabled) {
        FirebaseCrashlytics.getInstance().log(message);
    }
}
 
Example #22
Source File: CrashUtil.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public static void registerUserData() {
    if (crashlyticsEnabled) {
        FirebaseCrashlytics.getInstance().setUserId(ReportingUtils.getUser());
    }
}
 
Example #23
Source File: CrashUtil.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public static void reportException(Throwable e) {
    if (crashlyticsEnabled) {
        FirebaseCrashlytics.getInstance().recordException(e);
    }
}
 
Example #24
Source File: EventCollector.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
static public void logException(Throwable e, String desc) {
	if(!mDisabled) {
		FirebaseCrashlytics.getInstance().log(desc);
		logException(e, 0);
	}
}
 
Example #25
Source File: MainApplication.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
public void onEventMainThread(Logger.CrashReportEvent e) {
    FirebaseCrashlytics.getInstance().recordException(e.getError());
}
 
Example #26
Source File: TindroidApp.java    From tindroid with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    try {
        PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
        sAppVersion = pi.versionName;
        sAppBuild = pi.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, "Failed to retrieve app version", e);
    }

    // Disable Crashlytics for debug builds.
    FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(!BuildConfig.DEBUG);

    BroadcastReceiver br = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String token = intent.getStringExtra("token");
            if (token != null && !token.equals("") && sTinodeCache != null) {
                sTinodeCache.setDeviceToken(token);
            }
        }
    };
    LocalBroadcastManager.getInstance(this).registerReceiver(br, new IntentFilter("FCM_REFRESH_TOKEN"));

    createNotificationChannel();

    ProcessLifecycleOwner.get().getLifecycle().addObserver(this);

    // Listen to connectivity changes.
    ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    if (cm == null) {
        return;
    }
    NetworkRequest req = new NetworkRequest.
            Builder().addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET).build();
    cm.registerNetworkCallback(req, new ConnectivityManager.NetworkCallback() {
            @Override
            public void onAvailable(@NonNull Network network) {
                super.onAvailable(network);
                if (sTinodeCache != null) {
                    sTinodeCache.reconnectNow(true, false, false);
                }
            }
        });

    // Check if preferences already exist. If not, create them.
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    sServerHost = pref.getString("pref_hostName", null);
    if (TextUtils.isEmpty(sServerHost)) {
        // No preferences found. Save default values.
        SharedPreferences.Editor editor = pref.edit();
        sServerHost = getDefaultHostName(this);
        sUseTLS = getDefaultTLS();
        editor.putString("pref_hostName", sServerHost);
        editor.putBoolean("pref_useTLS", sUseTLS);
        editor.apply();
    } else {
        sUseTLS = pref.getBoolean("pref_useTLS", false);
    }
}
 
Example #27
Source File: EventCollector.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
public static void collectSessionData(String key, String value) {
	if(!mDisabled) {
		FirebaseCrashlytics.getInstance().setCustomKey(key, value);
	}
}
 
Example #28
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 #29
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 #30
Source File: ClusterMapContributeEditActivity.java    From intra42 with Apache License 2.0 4 votes vote down vote up
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
    Toast.makeText(app, R.string.error, Toast.LENGTH_SHORT).show();
    FirebaseCrashlytics.getInstance().log("onCancelled:" + databaseError);
}