File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
src/main/java/com/google/firebase/example/crashlytics Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ dependencies {
3838 implementation(" androidx.appcompat:appcompat:1.7.0" )
3939
4040 // Import the BoM for the Firebase platform
41- implementation(platform(" com.google.firebase:firebase-bom:33.6 .0" ))
41+ implementation(platform(" com.google.firebase:firebase-bom:33.8 .0" ))
4242
4343 // Add the dependencies for the Crashlytics and Analytics libraries
4444 // When using the BoM, you don't specify versions in Firebase library dependencies
Original file line number Diff line number Diff line change 77import android .view .ViewGroup ;
88import android .widget .Button ;
99
10+ import com .google .firebase .crashlytics .CustomKeysAndValues ;
1011import com .google .firebase .crashlytics .FirebaseCrashlytics ;
1112
1213public class MainActivity extends AppCompatActivity {
@@ -80,6 +81,22 @@ public void logCaughtEx() {
8081 // [END crash_log_caught_ex]
8182 }
8283
84+ public void logCaughtExWithCustomKeys () {
85+ // [START crash_log_caught_ex_custom_keys]
86+ try {
87+ methodThatThrows ();
88+ } catch (Exception e ) {
89+ CustomKeysAndValues keysAndValues = new CustomKeysAndValues .Builder ()
90+ .putString ("string key" , "string value" )
91+ .putBoolean ("boolean key" , true )
92+ .putFloat ("float key" , Float .MAX_VALUE )
93+ .build ();
94+ FirebaseCrashlytics .getInstance ().recordException (e , keysAndValues );
95+ // handle your exception here
96+ }
97+ // [END crash_log_caught_ex_custom_keys]
98+ }
99+
83100 public void forceACrash () {
84101 // [START crash_force_crash]
85102 Button crashButton = new Button (this );
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import android.view.ViewGroup
55import android.widget.Button
66import androidx.appcompat.app.AppCompatActivity
77import com.google.firebase.crashlytics.crashlytics
8+ import com.google.firebase.crashlytics.recordException
89import com.google.firebase.crashlytics.setCustomKeys
910import com.google.firebase.Firebase
1011
@@ -77,6 +78,21 @@ class MainActivity : AppCompatActivity() {
7778 // [END crash_log_caught_ex]
7879 }
7980
81+ fun logCaughtExWithCustomKeys () {
82+ // [START crash_log_caught_ex_custom_keys]
83+ try {
84+ methodThatThrows()
85+ } catch (e: Exception ) {
86+ Firebase .crashlytics.recordException(e) {
87+ key(" string key" , " string value" )
88+ key(" boolean key" , true )
89+ key(" float key" , Float .MAX_VALUE )
90+ }
91+ // handle your exception here
92+ }
93+ // [END crash_log_caught_ex_custom_keys]
94+ }
95+
8096 fun forceACrash () {
8197 // [START crash_force_crash]
8298 val crashButton = Button (this )
You can’t perform that action at this time.
0 commit comments