Created
July 24, 2013 16:08
-
-
Save joshdholtz/6072011 to your computer and use it in GitHub Desktop.
Using Sentry-Android, setting up in sublcassed Application, with a CaptureListener to show if using wifi - Screenshot of success http://i.imgur.com/n0LcGfM.png
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| package="com.joshdholtz.sentry" | |
| android:versionCode="1" | |
| android:versionName="1.0" > | |
| <uses-sdk | |
| android:minSdkVersion="8" | |
| android:targetSdkVersion="8" /> | |
| <uses-permission android:name="android.permission.INTERNET" /> | |
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
| <application | |
| android:allowBackup="true" | |
| android:icon="@drawable/ic_launcher" | |
| android:label="@string/app_name" | |
| android:theme="@style/AppTheme" | |
| android:name="com.joshdholtz.sentry.SentryApplication" > | |
| <activity | |
| android:name="com.joshdholtz.sentry.MainActivity" | |
| android:label="@string/app_name" > | |
| <intent-filter> | |
| <action android:name="android.intent.action.MAIN" /> | |
| <category android:name="android.intent.category.LAUNCHER" /> | |
| </intent-filter> | |
| </activity> | |
| </application> | |
| </manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.joshdholtz.sentry; | |
| import org.json.JSONException; | |
| import com.joshdholtz.sentry.Sentry.SentryEventBuilder; | |
| import com.joshdholtz.sentry.Sentry.SentryEventCaptureListener; | |
| import android.app.Application; | |
| import android.net.ConnectivityManager; | |
| import android.net.NetworkInfo; | |
| public class SentryApplication extends Application { | |
| @Override | |
| public void onCreate() { | |
| super.onCreate(); | |
| // Sentry will look for uncaught exceptions from previous runs and send them | |
| Sentry.init(this, "YOUR-DSN"); | |
| // Sets a listener to intercept the SentryEventBuilder before | |
| // each capture to set values that could change state | |
| Sentry.setCaptureListener(new SentryEventCaptureListener() { | |
| @Override | |
| public SentryEventBuilder beforeCapture(SentryEventBuilder builder) { | |
| // Needs permission - <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
| ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); | |
| NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); | |
| // Sets extra key if wifi is connected | |
| try { | |
| builder.getExtra().put("wifi", String.valueOf(mWifi.isConnected())); | |
| } catch (JSONException e) {} | |
| return builder; | |
| } | |
| }); | |
| // Capture event | |
| Sentry.captureEvent(new Sentry.SentryEventBuilder() | |
| .setMessage("Being so awesome at stuff") | |
| .setCulprit("Josh D Holtz") | |
| .setTimestamp(System.currentTimeMillis()) | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment