Skip to content

Instantly share code, notes, and snippets.

@pixelknitter
Created October 15, 2012 21:31
Show Gist options
  • Save pixelknitter/3895670 to your computer and use it in GitHub Desktop.
Save pixelknitter/3895670 to your computer and use it in GitHub Desktop.
Android Code Snippets for Crittercism Docs
// instantiate metadata json object
JSONObject metadata = new JSONObject();
// add arbitrary metadata
metadata.put("user_id", 123);
metadata.put("name", "John Doe");
// send metadata to crittercism (asynchronously)
Crittercism.setMetadata(metadata);
// Did the user get here before crashing?
String breadcrumb = "My Breadcrumb";
Crittercism.leaveBreadcrumb(breadcrumb);
boolean optOutStatus = Crittercism.getOptOutStatus();
try
{
throw new Exception("Exception Reason");
}
catch (Exception exception)
{
Crittercism.logHandledException(exception);
}
// create the JSONObject. (Do not forget to import org.json.JSONObject!)
JSONObject crittercismConfig = new JSONObject();
try
{
crittercismConfig.put("shouldCollectLogcat", true); // send logcat data for devices with API Level 16 and higher
}
catch (JSONException je){}
Crittercism.init(getApplicationContext(), "CRITTERCISM_APP_ID", crittercismConfig);
<uses-permission android:name="android.permission.READ_LOGS"/>
import com.crittercism.app.Crittercism;
import java.org.JSONObject;
import java.org.JSONException;
...
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
JSONObject crittercismConfiguration = new JSONObject();
try {
crittercismConfiguration.put("installNdk", true);
} catch(JSONException ex) {
Log.e("onCreate", "Failed putting a value to JSON.");
return;
}
Crittercism.init(getApplicationContext(), "Crittercism App ID", crittercismConfiguration);
// Any other code here.
}
// create the JSONObject. (Do not forget to import org.json.JSONObject!)
String myCustomNotificationTitle = "My Notification Title";
String myCustomVersionName = "My Custom Version Name";
JSONObject crittercismConfig = new JSONObject();
try
{
crittercismConfig.put("delaySendingAppLoad", true); // send app load data with Crittercism.sendAppLoadData()
crittercismConfig.put("notificationTitle", myCustomNotificationTitle);
crittercismConfig.put("shouldCollectLogcat", true); // necessary for collecting logcat data on Android Jelly Bean devices.
crittercismConfig.put("customVersionName", myCustomVersionName);
}
catch (JSONException je){}
Crittercism.init(getApplicationContext(), ""CRITTERCISM_APP_ID"", crittercismConfig);
Crittercism.setUsername("custom-username-here");
boolean optOutStatus = true;
Crittercism.setOptOutStatus(optOutStatus);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment