android.json 6.9 KB

123456
  1. {
  2. "html": "<div class=\"section\" id=\"installation\">\n<h2>Installation</h2>\n<p>Using Gradle (Android Studio) in your <code class=\"docutils literal\"><span class=\"pre\">app/build.gradle</span></code> add:</p>\n<div class=\"highlight-groovy\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #111111\">compile</span> <span style=\"color: #e8535a\">&#39;io.sentry:sentry-android:1.6.3&#39;</span>\n</pre></div>\n</div>\n<p>For other dependency managers see the <a class=\"reference external\" href=\"https://search.maven.org/#artifactdetails%7Cio.sentry%7Csentry-android%7C1.6.3%7Cjar\">central Maven repository</a>.</p>\n</div>\n\n\n<div class=\"section\" id=\"usage\">\n<h2>Usage</h2>\n<p>Now you can use <code class=\"docutils literal\"><span class=\"pre\">Sentry</span></code> to capture events anywhere in your application:</p>\n<div class=\"highlight-java\"><div class=\"highlight\" style=\"background: #ffffff\"><pre style=\"line-height: 125%\"><span></span><span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.context.Context</span><span style=\"color: #4b4f5c\">;</span>\n<span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.event.BreadcrumbBuilder</span><span style=\"color: #4b4f5c\">;</span>\n<span style=\"color: #2eb0f7\">import</span> <span style=\"color: #111111\">io.sentry.event.UserBuilder</span><span style=\"color: #4b4f5c\">;</span>\n\n<span style=\"color: #2eb0f7\">public</span> <span style=\"color: #2eb0f7\">class</span> <span style=\"color: #111111\">MyClass</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">/**</span>\n<span style=\"color: #34c08b; font-style: italic\"> * An example method that throws an exception.</span>\n<span style=\"color: #34c08b; font-style: italic\"> */</span>\n <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">unsafeMethod</span><span style=\"color: #4b4f5c\">()</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #2eb0f7\">throw</span> <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">UnsupportedOperationException</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">&quot;You shouldn&#39;t call this!&quot;</span><span style=\"color: #4b4f5c\">);</span>\n <span style=\"color: #4b4f5c\">}</span>\n\n <span style=\"color: #34c08b; font-style: italic\">/**</span>\n<span style=\"color: #34c08b; font-style: italic\"> * Note that the ``Sentry.init`` method must be called before the static API</span>\n<span style=\"color: #34c08b; font-style: italic\"> * is used, otherwise a ``NullPointerException`` will be thrown.</span>\n<span style=\"color: #34c08b; font-style: italic\"> */</span>\n <span style=\"color: #2eb0f7\">void</span> <span style=\"color: #111111\">logWithStaticAPI</span><span style=\"color: #4b4f5c\">()</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">/*</span>\n<span style=\"color: #34c08b; font-style: italic\"> Record a breadcrumb in the current context which will be sent</span>\n<span style=\"color: #34c08b; font-style: italic\"> with the next event(s). By default the last 100 breadcrumbs are kept.</span>\n<span style=\"color: #34c08b; font-style: italic\"> */</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">getContext</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">recordBreadcrumb</span><span style=\"color: #4b4f5c\">(</span>\n <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">BreadcrumbBuilder</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">setMessage</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">&quot;User made an action&quot;</span><span style=\"color: #4b4f5c\">).</span><span style=\"color: #a47ac6\">build</span><span style=\"color: #4b4f5c\">()</span>\n <span style=\"color: #4b4f5c\">);</span>\n\n <span style=\"color: #34c08b; font-style: italic\">// Set the user in the current context.</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">getContext</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">setUser</span><span style=\"color: #4b4f5c\">(</span>\n <span style=\"color: #2eb0f7\">new</span> <span style=\"color: #111111\">UserBuilder</span><span style=\"color: #4b4f5c\">().</span><span style=\"color: #a47ac6\">setEmail</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">&quot;hello@sentry.io&quot;</span><span style=\"color: #4b4f5c\">).</span><span style=\"color: #a47ac6\">build</span><span style=\"color: #4b4f5c\">()</span>\n <span style=\"color: #4b4f5c\">);</span>\n\n <span style=\"color: #34c08b; font-style: italic\">/*</span>\n<span style=\"color: #34c08b; font-style: italic\"> This sends a simple event to Sentry using the statically stored instance</span>\n<span style=\"color: #34c08b; font-style: italic\"> that was created in the ``main`` method.</span>\n<span style=\"color: #34c08b; font-style: italic\"> */</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">capture</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #e8535a\">&quot;This is a test&quot;</span><span style=\"color: #4b4f5c\">);</span>\n\n <span style=\"color: #2eb0f7\">try</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #111111\">unsafeMethod</span><span style=\"color: #4b4f5c\">();</span>\n <span style=\"color: #4b4f5c\">}</span> <span style=\"color: #2eb0f7\">catch</span> <span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">Exception</span> <span style=\"color: #111111\">e</span><span style=\"color: #4b4f5c\">)</span> <span style=\"color: #4b4f5c\">{</span>\n <span style=\"color: #34c08b; font-style: italic\">// This sends an exception event to Sentry using the statically stored instance</span>\n <span style=\"color: #34c08b; font-style: italic\">// that was created in the ``main`` method.</span>\n <span style=\"color: #111111\">Sentry</span><span style=\"color: #4b4f5c\">.</span><span style=\"color: #a47ac6\">capture</span><span style=\"color: #4b4f5c\">(</span><span style=\"color: #111111\">e</span><span style=\"color: #4b4f5c\">);</span>\n <span style=\"color: #4b4f5c\">}</span>\n <span style=\"color: #4b4f5c\">}</span>\n<span style=\"color: #4b4f5c\">}</span>\n</pre></div>\n</div>\n</div>\n",
  3. "link": "https://docs.getsentry.com/platforms/android/",
  4. "id": "android",
  5. "name": "Android"
  6. }