|
1 | 1 | package com.google.firebase.example.crashlytics;
|
2 | 2 |
|
3 | 3 | import android.os.Bundle;
|
| 4 | +import androidx.appcompat.app.AppCompatActivity; |
| 5 | +import android.util.Log; |
4 | 6 | import android.view.View;
|
5 | 7 | import android.view.ViewGroup;
|
6 | 8 | import android.widget.Button;
|
7 |
| -import androidx.appcompat.app.AppCompatActivity; |
| 9 | + |
8 | 10 | import com.google.firebase.crashlytics.FirebaseCrashlytics;
|
9 | 11 |
|
10 | 12 | public class MainActivity extends AppCompatActivity {
|
11 | 13 |
|
12 |
| - @Override |
13 |
| - protected void onCreate(Bundle savedInstanceState) { |
14 |
| - super.onCreate(savedInstanceState); |
15 |
| - } |
16 |
| - |
17 |
| - public void setKeysBasic() { |
18 |
| - // [START crash_set_keys_basic] |
19 |
| - FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
| 14 | + @Override |
| 15 | + protected void onCreate(Bundle savedInstanceState) { |
| 16 | + super.onCreate(savedInstanceState); |
| 17 | + } |
20 | 18 |
|
21 |
| - crashlytics.setCustomKey("my_string_key", "foo" /* string value */); |
| 19 | + public void setKeysBasic() { |
| 20 | + // [START crash_set_keys_basic] |
| 21 | + FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
22 | 22 |
|
23 |
| - crashlytics.setCustomKey("my_bool_key", true /* boolean value */); |
| 23 | + crashlytics.setCustomKey("my_string_key", "foo" /* string value */); |
24 | 24 |
|
25 |
| - crashlytics.setCustomKey("my_double_key", 1.0 /* double value */); |
| 25 | + crashlytics.setCustomKey("my_bool_key", true /* boolean value */); |
26 | 26 |
|
27 |
| - crashlytics.setCustomKey("my_float_key", 1.0f /* float value */); |
| 27 | + crashlytics.setCustomKey("my_double_key", 1.0 /* double value */); |
28 | 28 |
|
29 |
| - crashlytics.setCustomKey("my_int_key", 1 /* int value */); |
30 |
| - // [END crash_set_keys_basic] |
31 |
| - } |
| 29 | + crashlytics.setCustomKey("my_float_key", 1.0f /* float value */); |
32 | 30 |
|
33 |
| - public void resetKey() { |
34 |
| - // [START crash_re_set_key] |
35 |
| - FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
| 31 | + crashlytics.setCustomKey("my_int_key", 1 /* int value */); |
| 32 | + // [END crash_set_keys_basic] |
| 33 | + } |
36 | 34 |
|
37 |
| - crashlytics.setCustomKey("current_level", 3); |
38 |
| - crashlytics.setCustomKey("last_UI_action", "logged_in"); |
39 |
| - // [END crash_re_set_key] |
40 |
| - } |
| 35 | + public void resetKey() { |
| 36 | + // [START crash_re_set_key] |
| 37 | + FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); |
41 | 38 |
|
42 |
| - public void logReportAndPrint() { |
43 |
| - // [START crash_log_report_and_print] |
44 |
| - FirebaseCrashlytics.getInstance().log("message"); |
45 |
| - // [END crash_log_report_and_print] |
46 |
| - } |
| 39 | + crashlytics.setCustomKey("current_level", 3); |
| 40 | + crashlytics.setCustomKey("last_UI_action", "logged_in"); |
| 41 | + // [END crash_re_set_key] |
| 42 | + } |
47 | 43 |
|
48 |
| - public void logReportOnly() { |
49 |
| - // [START crash_log_report_only] |
50 |
| - FirebaseCrashlytics.getInstance().log("message"); |
51 |
| - // [END crash_log_report_only] |
52 |
| - } |
| 44 | + public void logReportAndPrint() { |
| 45 | + // [START crash_log_report_and_print] |
| 46 | + FirebaseCrashlytics.getInstance().log("message"); |
| 47 | + // [END crash_log_report_and_print] |
| 48 | + } |
53 | 49 |
|
54 |
| - public void enableAtRuntime() { |
55 |
| - // [START crash_enable_at_runtime] |
56 |
| - FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true); |
57 |
| - // [END crash_enable_at_runtime] |
58 |
| - } |
| 50 | + public void logReportOnly() { |
| 51 | + // [START crash_log_report_only] |
| 52 | + FirebaseCrashlytics.getInstance().log("message"); |
| 53 | + // [END crash_log_report_only] |
| 54 | + } |
59 | 55 |
|
60 |
| - public void setUserId() { |
61 |
| - // [START crash_set_user_id] |
62 |
| - FirebaseCrashlytics.getInstance().setUserId("user123456789"); |
63 |
| - // [END crash_set_user_id] |
64 |
| - } |
| 56 | + public void enableAtRuntime() { |
| 57 | + // [START crash_enable_at_runtime] |
| 58 | + FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(true); |
| 59 | + // [END crash_enable_at_runtime] |
| 60 | + } |
65 | 61 |
|
66 |
| - public void methodThatThrows() throws Exception { |
67 |
| - throw new Exception(); |
68 |
| - } |
| 62 | + public void setUserId() { |
| 63 | + // [START crash_set_user_id] |
| 64 | + FirebaseCrashlytics.getInstance().setUserId("user123456789"); |
| 65 | + // [END crash_set_user_id] |
| 66 | + } |
69 | 67 |
|
70 |
| - public void logCaughtEx() { |
71 |
| - // [START crash_log_caught_ex] |
72 |
| - try { |
73 |
| - methodThatThrows(); |
74 |
| - } catch (Exception e) { |
75 |
| - FirebaseCrashlytics.getInstance().recordException(e); |
76 |
| - // handle your exception here |
| 68 | + public void methodThatThrows() throws Exception { |
| 69 | + throw new Exception(); |
77 | 70 | }
|
78 |
| - // [END crash_log_caught_ex] |
79 |
| - } |
80 | 71 |
|
81 |
| - public void logCaughtExWithCustomKeys() { |
82 |
| - // [START crash_log_caught_ex_custom_keys] |
83 |
| - try { |
84 |
| - methodThatThrows(); |
85 |
| - } catch (Exception e) { |
86 |
| - FirebaseCrashlytics.getInstance() |
87 |
| - .recordException(e, Map.of("key_1", "value_1", "key_2", "value_2")); |
88 |
| - // handle your exception here |
| 72 | + public void logCaughtEx() { |
| 73 | + // [START crash_log_caught_ex] |
| 74 | + try { |
| 75 | + methodThatThrows(); |
| 76 | + } catch (Exception e) { |
| 77 | + FirebaseCrashlytics.getInstance().recordException(e); |
| 78 | + // handle your exception here |
| 79 | + } |
| 80 | + // [END crash_log_caught_ex] |
89 | 81 | }
|
90 |
| - // [END crash_log_caught_ex_custom_keys] |
| 82 | + |
| 83 | + public void logCaughtExWithCustomKeys() { |
| 84 | + // [START crash_log_caught_ex_custom_keys] |
| 85 | + try { |
| 86 | + methodThatThrows(); |
| 87 | + } catch (Exception e) { |
| 88 | + FirebaseCrashlytics.getInstance().recordException( |
| 89 | + e, |
| 90 | + Map.of("key_1", "value_1", "key_2", "value_2")); |
| 91 | + // handle your exception here |
| 92 | + } |
| 93 | + // [END crash_log_caught_ex_custom_keys] |
91 | 94 | }
|
92 | 95 |
|
93 |
| - public void forceACrash() { |
94 |
| - // [START crash_force_crash] |
95 |
| - Button crashButton = new Button(this); |
96 |
| - crashButton.setText("Crash!"); |
97 |
| - crashButton.setOnClickListener( |
98 |
| - new View.OnClickListener() { |
99 |
| - public void onClick(View view) { |
100 |
| - throw new RuntimeException(); // Force a crash |
101 |
| - } |
| 96 | + public void forceACrash() { |
| 97 | + // [START crash_force_crash] |
| 98 | + Button crashButton = new Button(this); |
| 99 | + crashButton.setText("Crash!"); |
| 100 | + crashButton.setOnClickListener(new View.OnClickListener() { |
| 101 | + public void onClick(View view) { |
| 102 | + throw new RuntimeException(); // Force a crash |
| 103 | + } |
102 | 104 | });
|
103 | 105 |
|
104 |
| - addContentView( |
105 |
| - crashButton, |
106 |
| - new ViewGroup.LayoutParams( |
107 |
| - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); |
108 |
| - // [END crash_force_crash] |
109 |
| - } |
| 106 | + addContentView(crashButton, new ViewGroup.LayoutParams( |
| 107 | + ViewGroup.LayoutParams.MATCH_PARENT, |
| 108 | + ViewGroup.LayoutParams.WRAP_CONTENT)); |
| 109 | + // [END crash_force_crash] |
| 110 | + } |
110 | 111 | }
|
0 commit comments