/
MainActivity.java
107 lines (86 loc) · 3.05 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.google.firebase.example.crashlytics;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.crashlytics.android.Crashlytics;
import io.fabric.sdk.android.Fabric;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void setKeysBasic(String key) {
// [START crash_set_keys_basic]
Crashlytics.setString(key, "foo" /* string value */);
Crashlytics.setBool(key, true /* boolean value */);
Crashlytics.setDouble(key, 1.0 /* double value */);
Crashlytics.setFloat(key, 1.0f /* float value */);
Crashlytics.setInt(key, 1 /* int value */);
// [END crash_set_keys_basic]
}
public void resetKey() {
// [START crash_re_set_key]
Crashlytics.setInt("current_level", 3);
Crashlytics.setString("last_UI_action", "logged_in");
// [END crash_re_set_key]
}
public void logReportAndPrint() {
// [START crash_log_report_and_print]
Crashlytics.log(Log.DEBUG, "tag", "message");
// [END crash_log_report_and_print]
}
public void logReportOnly() {
// [START crash_log_report_only]
Crashlytics.log("message");
// [END crash_log_report_only]
}
public void enableAtRuntime() {
// [START crash_enable_at_runtime]
Fabric.with(this, new Crashlytics());
// [END crash_enable_at_runtime]
}
public void setUserId() {
// [START crash_set_user_id]
Crashlytics.setUserIdentifier("user123456789");
// [END crash_set_user_id]
}
public void methodThatThrows() throws Exception {
throw new Exception();
}
public void logCaughtEx() {
// [START crash_log_caught_ex]
try {
methodThatThrows();
} catch (Exception e) {
Crashlytics.logException(e);
// handle your exception here
}
// [END crash_log_caught_ex]
}
public void enableDebugMode() {
// [START crash_enable_debug_mode]
final Fabric fabric = new Fabric.Builder(this)
.kits(new Crashlytics())
.debuggable(true) // Enables Crashlytics debugger
.build();
Fabric.with(fabric);
// [END crash_enable_debug_mode]
}
public void forceACrash() {
// [START crash_force_crash]
Button crashButton = new Button(this);
crashButton.setText("Crash!");
crashButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Crashlytics.getInstance().crash(); // Force a crash
}
});
addContentView(crashButton, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
// [END crash_force_crash]
}
}