Java Code Examples for com.crashlytics.android.Crashlytics#getInstance()

The following examples show how to use com.crashlytics.android.Crashlytics#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: SetupApplication.java    From octoandroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void log(int priority, String tag, String message, Throwable t) {
    if (priority == Log.VERBOSE || priority == Log.DEBUG || priority == Log.INFO) {
        return;
    }

    if (Crashlytics.getInstance() == null) return; // Should never happen
    Crashlytics.setInt(CRASHLYTICS_KEY_PRIORITY, priority);
    Crashlytics.setString(CRASHLYTICS_KEY_TAG, tag);
    Crashlytics.setString(CRASHLYTICS_KEY_MESSAGE, message);

    if (t == null) {
        Crashlytics.logException(new Exception(message));
    } else {
        Crashlytics.logException(t);
    }
}
 
Example 2
Source File: FabricPrivacy.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void logException(Throwable throwable) {
    try {
        final Crashlytics crashlytics = Crashlytics.getInstance();
        crashlytics.core.logException(throwable);
    } catch (NullPointerException | IllegalStateException e) {
        if (L.isEnabled(L.CORE))
            log.debug("Ignoring opted out non-initialized log: " + throwable);
    }
}
 
Example 3
Source File: FabricPrivacy.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void log(String msg) {
    try {
        final Crashlytics crashlytics = Crashlytics.getInstance();
        crashlytics.core.log(msg);
    } catch (NullPointerException | IllegalStateException e) {
        if (L.isEnabled(L.CORE))
            log.debug("Ignoring opted out non-initialized log: " + msg);
    }
}
 
Example 4
Source File: FabricPrivacy.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void log(int priority, String tag, String msg) {
    try {
        final Crashlytics crashlytics = Crashlytics.getInstance();
        crashlytics.core.log(priority, tag, msg);
    } catch (NullPointerException | IllegalStateException e) {
        if (L.isEnabled(L.CORE))
            log.debug("Ignoring opted out non-initialized log: " + msg);
    }
}
 
Example 5
Source File: FlutterCrashlyticsPlugin.java    From flutter_crashlytics with BSD 2-Clause "Simplified" License 4 votes vote down vote up
void onInitialisedMethodCall(MethodCall call, MethodChannel.Result result) {
    final CrashlyticsCore core = Crashlytics.getInstance().core;
    switch (call.method) {
        case "log":
            if (call.arguments instanceof String) {
                core.log(call.arguments.toString());
            } else {
                try {
                    final List<Object> info = (List<Object>) call.arguments;
                    core.log(parseStringOrEmpty(info.get(0)) + ": " + info.get(1) + " " + info.get(2));
                } catch (ClassCastException ex) {
                    Log.d("FlutterCrashlytics", "" + ex.getMessage());
                }
            }
            result.success(null);
            break;
        case "setInfo":
            final Object currentInfo = call.argument("value");
            if (currentInfo instanceof String) {
                core.setString((String) call.argument("key"), (String) call.argument("value"));
            } else if (currentInfo instanceof Integer) {
                core.setInt((String) call.argument("key"), (Integer) call.argument("value"));
            } else if (currentInfo instanceof Double) {
                core.setDouble((String) call.argument("key"), (Double) call.argument("value"));
            } else if (currentInfo instanceof Boolean) {
                core.setBool((String) call.argument("key"), (Boolean) call.argument("value"));
            } else if (currentInfo instanceof Float) {
                core.setFloat((String) call.argument("key"), (Float) call.argument("value"));
            } else if (currentInfo instanceof Long) {
                core.setLong((String) call.argument("key"), (Long) call.argument("value"));
            } else {
                core.log("ignoring unknown type with key " + call.argument("key") + "and value "
                        + call.argument("value"));
            }
            result.success(null);
            break;
        case "setUserInfo":
            core.setUserEmail((String) call.argument("email"));
            core.setUserName((String) call.argument("name"));
            core.setUserIdentifier((String) call.argument("id"));
            result.success(null);
            break;
        case "reportCrash":
            final Map<String, Object> exception = (Map<String, Object>) call.arguments;
            final boolean forceCrash = tryParseForceCrash(exception.get("forceCrash"));
            final FlutterException throwable = Utils.create(exception);
            if (forceCrash) {
                //Start a new activity to not crash directly under onMethod call, or it will crash JNI instead of a clean exception
                final Intent intent = new Intent(context, CrashActivity.class);
                intent.putExtra("exception", throwable);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                context.startActivity(intent);
            } else {
                Log.d("Crashlytics", "this thing is reporting");
                core.logException(throwable);
            }

            result.success(null);
            break;
        default:
            result.notImplemented();
            break;
    }
}