2

I want to use HockeyApp tool to send an crash report. So I am new to this crash reports. I have looked through these website but nothing get's in my mind.I tried setup as per instruction they have shown.

But was unable to receive crash reports in website tool. So Can any one provide an example for crash reporting tool using only Hockey App.

test1.java

 public class test1 extends AppCompatActivity {

    private static final String TAG = "test1";
    private static final String APP_ID = "2aac21928b1242a19fa49ae4cf69a552";
    private Button errorBtn;
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        errorBtn = (Button) findViewById(R.id.showSnackbarButton);
        setContentView(R.layout.activity_test1);
        textView=(TextView)findViewById(R.id.someText);

        errorBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                
                File file = new File("E://file.txt");
                try {
                    FileReader fr = new FileReader(file);
                } catch (FileNotFoundException e) {
                    Log.d(TAG, "FilenotFound_Demo");
                    e.printStackTrace();
                }
            }
        });
        checkForUpdates();
    }

    @Override
    public void onResume() {
        super.onResume();
        // ... your own onResume implementation
        checkForCrashes();
    }

    @Override
    public void onPause() {
        super.onPause();
        unregisterManagers();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        unregisterManagers();
    }


    private void checkForCrashes() {
        CrashManager.register(this, APP_ID, new CrashManagerListener() {
            public boolean shouldAutoUploadCrashes() {
                return true;
            }
        });

    }

    private void checkForUpdates() {
        // Remove this for store builds!
        UpdateManager.register(this,APP_ID);
    }

    private void unregisterManagers() {
        UpdateManager.unregister();
    }
}

My build Module:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"
    defaultConfig {
        applicationId "com.example.river.tessting"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        manifestPlaceholders = [HOCKEYAPP_APP_ID: "2aac21928b1242a19fa49ae4cf69a552"]
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'net.hockeyapp.android:HockeySDK:4.1.5'
    testCompile 'junit:junit:4.12'
}
repositories {
    jcenter()
}
opalfire
  • 93
  • 1
  • 9
  • Are you just trying to test if crash functionality is working? The SDK is configured to catch and send unhandled exceptions, currently handled exceptions are not supported on the HockeyApp platform. If you are just checking if it's functioning as expected, you can throw an exception on button click without catching it. – Shawn Dyas Aug 02 '17 at 19:23
  • @Shawn Dyas Yes , I was testing if crash functionality is working..if an crash occurs it should directly reported to developer [Hockeyapp](https://rink.hockeyapp.net/users/sign_in) account. This was my first point. Another point how send logs to Hockeyapp for handled expections and above code is correct or not. – opalfire Aug 03 '17 at 10:54

1 Answers1

1

Crash reports are sent the next time the app starts when you crash your app.

Code Snippet for triggering UnhandledException

        Button crashBtn = (Button) findViewById(R.id.crash_Btn);
        crashBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                throw new NullPointerException();
            }
        });

HockeyApp don't support handledException on Android. But you can use the UserMetrics to track it as a workaround.

Use Custom Event to track HandledException information :

    Button handledException = (Button) findViewById(R.id.handledException_Btn);
    handledException.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                throw new NullPointerException();
            }catch (Exception e){

                // add this wherever you want to track a custom event and attach properties or measurements to it
                HashMap<String, String> properties = new HashMap<>();
                properties.put("StackTrace", e.getStackTrace().toString());
                properties.put("Cause", e.getLocalizedMessage());

                HashMap<String, Double> measurements = new HashMap<>();
                measurements.put("YOUR_Measurement", 1.0);

                MetricsManager.trackEvent("YOUR_EVENT_NAME", properties, measurements);

            }

        }
    });

But, on HockeyApp dashboard you only can see the event name in Events tab. To find the properties of custom events, you have to link to Application Insight. HockeyApp has the documentation on this which you can refer to.

Kevin Li
  • 2,258
  • 1
  • 9
  • 18
  • Before finishing these i like to know was my build was correct @Kevin – opalfire Aug 04 '17 at 11:27
  • @opalfire your integration code is correct. But the button action triggers a handledException which can't be detected by HockeySDK. So, if you want to test the crash report feature, you have to remove the try-catch. – Kevin Li Aug 07 '17 at 02:18