{ "html": "
\n

Installation

\n

Using Gradle (Android Studio) in your app/build.gradle add:

\n
compile 'io.sentry:sentry-android:1.6.3'\n
\n
\n

For other dependency managers see the central Maven repository.

\n
\n\n\n
\n

Usage

\n

Now you can use Sentry to capture events anywhere in your application:

\n
import io.sentry.context.Context;\nimport io.sentry.event.BreadcrumbBuilder;\nimport io.sentry.event.UserBuilder;\n\npublic class MyClass {\n    /**\n     * An example method that throws an exception.\n     */\n    void unsafeMethod() {\n        throw new UnsupportedOperationException("You shouldn't call this!");\n    }\n\n    /**\n     * Note that the ``Sentry.init`` method must be called before the static API\n     * is used, otherwise a ``NullPointerException`` will be thrown.\n     */\n    void logWithStaticAPI() {\n        /*\n        Record a breadcrumb in the current context which will be sent\n        with the next event(s). By default the last 100 breadcrumbs are kept.\n        */\n        Sentry.getContext().recordBreadcrumb(\n            new BreadcrumbBuilder().setMessage("User made an action").build()\n        );\n\n        // Set the user in the current context.\n        Sentry.getContext().setUser(\n            new UserBuilder().setEmail("hello@sentry.io").build()\n        );\n\n        /*\n        This sends a simple event to Sentry using the statically stored instance\n        that was created in the ``main`` method.\n        */\n        Sentry.capture("This is a test");\n\n        try {\n            unsafeMethod();\n        } catch (Exception e) {\n            // This sends an exception event to Sentry using the statically stored instance\n            // that was created in the ``main`` method.\n            Sentry.capture(e);\n        }\n    }\n}\n
\n
\n
\n", "link": "https://docs.getsentry.com/platforms/android/", "id": "android", "name": "Android" }