Created
October 15, 2012 21:31
-
-
Save pixelknitter/3895670 to your computer and use it in GitHub Desktop.
Android Code Snippets for Crittercism Docs
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
// 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); |
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
boolean optOutStatus = Crittercism.getOptOutStatus(); |
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
try | |
{ | |
throw new Exception("Exception Reason"); | |
} | |
catch (Exception exception) | |
{ | |
Crittercism.logHandledException(exception); | |
} |
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
// 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); |
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
<uses-permission android:name="android.permission.READ_LOGS"/> |
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
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. | |
} |
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
// 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); |
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
Crittercism.setUsername("custom-username-here"); |
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
boolean optOutStatus = true; | |
Crittercism.setOptOutStatus(optOutStatus); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment