Integrate Hockey App In Xamarin Android Application

Introduction

Hockey app is a platform for mobile developers which helps in the distribution of apps  for testing purpose. It provides various features like collecting the crash reports, getting user feedback, and collecting user metrics. We can think of Hockey app as an App Store for testing purposes. Hockey app supports different platforms like Android, IOS, Cordova, UWP, React Native, Unity and Xamarin. In this article, we will focus on Xamarin Android application. For the testing of Xamarin Android application, tester user just need to install the mobile app for Hockey app on their mobile device using which they will be able to see all the application they need to test and provide feedback.

Now let`s get more information about each feature.

Distribution of App for Testing:

  1. For distribution of an app, we just need to upload our app .apk (Android Application Package) file in Hockey app and then testers will be able to download and install the app on their mobile devices for testing through the mobile app for Hockey App.

  2. We can also control which user can see and install our app.

  3. If we have new version of our app, then tester will get a notification on their mobile device, that there is a new version available for the app. So that they can download, install and start testing.

Collect Crash Reports

  1. Just by integrating Hockey app SDK in our Xamarin Android application, our application can directly send the crash reports to Hockey app. No extra coding is required.

  2. We can get the details about the crash in our Hockey app dashboard with detailed stack trace including class name, method name and line number.

Get The User Feedback:

  1. User can provide the feedback for all the builds of our application through Hockey app website.

Collect The User Metrics

  • It provides detailed information about how users are interacting with our application. For example the number of downloads of our app, active users, unique devices experiencing the crash and much more. For more information click here.

In this article, we will create a simple Xamarin Android application in which when the user clicks on a button, we will throw an exception which will crash the application. The exception details should get logged in Hockey app.

So let's get started:

Steps

  1. To get started open Visual Studio 2015 and select File Menu=> New => Project option. It will open up a project dialog box as shown below (F: 1).


                                                    Figure 1

  2. Select the Blank App (Android) project template and enter the name of the project as HockeyAppDemo and click on Ok button. After clicking on Ok button, a blank Xamarin Android application will be created.

  3. We need to install the following package to integrate Hockey app in our application.
    Install-Package HockeySDK.Xamarin -Pre.
  4. To install the package, go to Tools=> NuGet Package Manager=> Package Manager Console option as shown below (F: 2).


                                                          Figure 2

  5. It will open up Package Manager Console window. Copy and paste the command from step 3 and hit enter to install the package.

  6. Next step is we need to get the package name for our application. We will need this, when we register our application with Hockey app. To get the package name, right click on project and select Properties option. It will open up a window. To get the Package Name select the Android Manifest option in that window as shown below (F: 3).

                                                             Figure 3

  7. Blank App (Android) project template will create a default activity for us (MainActivity.cs file with android layout Main.axml). Add the following code in Main.axml file.
    1. <?xml version="1.0" encoding="utf-8"?>  
    2.    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.       android:orientation="vertical"  
    4.       android:layout_width="fill_parent"  
    5.       android:layout_height="fill_parent">  
    6.       <Button  
    7.          android:id="@+id/btnClick"  
    8.          android:layout_width="fill_parent"  
    9.          android:layout_height="wrap_content"  
    10.       android:text="Click To Crash" />  
    11.    </LinearLayout>  
    The above code will add a button with simple text “Click To Crash”.

  8. Add the following code in MainActivity.cs file.
    1. using Android.App;  
    2. using Android.Widget;  
    3. using Android.OS;  
    4. using System;  
    5. using HockeyApp;  
    6. namespace HockeyAppDemo  
    7. {  
    8.     [Activity(Label = "Hockey App Demo", MainLauncher = true, Icon = "@drawable/icon")]  
    9.     public class MainActivity: Activity  
    10.     {  
    11.         protected override void OnCreate(Bundle bundle)  
    12.         {  
    13.             base.OnCreate(bundle);  
    14.             CrashManager.Register(this"<HockeyAppKey>");  
    15.             SetContentView(Resource.Layout.Main);  
    16.             Button button = FindViewById < Button > (Resource.Id.btnClick);  
    17.             button.Click += delegate  
    18.             {  
    19.                 throw new DivideByZeroException("Divide By Zero Exception");  
    20.             };  
    21.         }  
    22.     }  
    23. }  
    Now let`s go through the code:

    • When user clicks on a button, we are throwing a DivideByZeroException to crash the application.

    • CrashManager.Register method will configure our application to work with Hockey app. This method requires a Hockey App key.

  9. To get the Hockey app key, we need to sign in for Hockey app account. (If you don`t have an account, you can sign up for free Hockey app account. After sign up, you will get an email regarding the email verification. Verify the email to proceed further).

  10. After login, we will see a dashboard page. We can register our application by clicking on New App button on dashboard page as shown below (F: 4).


                                                    Figure 4

  11. After clicking on New App button, we will get a popup window as shown below (F: 5).


                                                       Figure 5

  12. As shown in above image, click on manually link to proceed further.

  13. After clicking manually link, we will get a form as shown below (F: 6).


                                                       Figure 6

    Select the platform as Android and enter the details as shown below (F: 7)


                                                          Figure 7

    Enter the title and package name we got from step 6. After filling all the detail, click on save button. Hockey app will create our application. After some processing, we will get a page where our App Id is displayed as shown below (F: 8).


                                                                Figure 8

    Copy this App Id and pass it as a parameter to CrashManager.Register method in MainActivity.cs file. (CrashManager.Register(this,”<YOUR APP ID>”))

  14. Now run the application using Ctrl+F5 shortcut key. Once it is deployed to emulator, click on Click to Crash button. After clicking on Click to Crash button, our application will crash because of the DivideByZeroException that we have thrown on button click event. Open the application again from the Apps screen in emulator. We will get an alert as shown below (F: 9).


                                        Figure 9

    Click on Send Report button to send the crash details to Hockey app. Go back to Hockey app website and refresh the page. We will be able to see that our crash report is logged in Hockey app as shown below (F: 10)


                                                          Figure 10

  15. Click on Crashes (1) link at the top as shown in above image. We will get a page which displays total number of crashes as shown below (F:11)


                                                             Figure 11

  16. Click on crash to get the crash details.

  17. After clicking on crash, we will get a page showing all the detail about the crash including stack trace and type of exception as shown below (F:12)


                                                             Figure 12

  18. Stack trace image is as shown below (F:13)


                                                 Figure 13

  19. Great  -- we were successfully able to test our application on emulator. But for other testers to test our application, we need to upload the .apk file for our application to Hockey app.

  20. To create the .apk file for our application, change the Solution Configuration for our project from Debug to Release mode as shown below (F: 14)


                                                          Figure 14

  21. Now run the application using Ctrl+F5 shortcut key. It will create an .apk file in bin\Release folder of our application as shown below (F: 15).


                                                             Figure 15

  22. We need to upload the HockeyAppDemo.HockeyAppDemo-Signed.apk to Hockey app.

  23. Now let's go back to Hockey app website to upload our .apk file. To upload .apk file to Hockey app, select the Versions option. It will display all the versions of our application as shown below (F: 16)


                                                             Figure 16

  24. Select the 1.0 version. It will display a new page. There will be a section called as Latest Files as shown below (F:17).


                                  Figure 17

  25. Just drag and drop HockeyAppDemo.HockeyAppDemo-Signed.apk file in Upload .apk file section as shown in above image.

  26. After the upload is complete, we will get a new page as shown below (F: 18) where we can enter the release notes for our application.


                                                                Figure 18

  27. After filling out the release notes, click on Next Step button.

  28. After clicking on Next Step button, we will get a Status page as shown below (F: 19)


                                                             Figure 19

    As shown in above image, installation option will allow our tester user to download and install the application through Hockey App Android Application. They will also get a notification when a new version of our application is released. Using the Restricted Download option, we can define which users can install this build of our application. Keep the default settings and click on Next Step button.

  29. After clicking on Next Step button, we will get a Notify page as shown below (F: 20)


                                                          Figure 20

  30. Notify page allows us to notify our tester users regarding the new version of our application. Click on the Send button to proceed further. When we click on Send button, tester user will get an email regarding the release of our application including the link to download and install the app.

  31. After clicking on Send button, we will get a page displaying all the release details as shown below (F: 21).


                                                          Figure 21

  32. Click on Done button.

  33. After clicking on done button, we will be redirected to an overview screen of our app in Hockey app dashboard.

  34. To download the Hockey app mobile application, open rink.io/sYMAmL5 link in mobile browser. We will get a page as shown below (F: 22).


                                     Figure 22

  35. Follow the steps shown in above image and download the Hockey app mobile application. After downloading the application, we need to sign in using Hockey app account credentials.

  36. After signing in, we will be able to see our application is listed in Android section as shown below (F: 23).


                                        Figure 23

  37. Select the application. After selecting it, we will get navigated to another screen as shown below (F: 24)


                               Figure 24

  38. As we can see in above image, we can see all the details of our application like version number, app size, release notes etc. We can download the application using the blue floating action button at the bottom of the screen as shown in above image. Once it is downloaded, we can install and start testing the application.

  39. To invite other members for testing our application, go back to our Hockey app website and select Users link and click on Invite User Button and as shown below (F:25)


                                                             Figure 25

  40. After clicking on Invite User button, we will get a form as shown below (F: 26) where we need to specify the email address for our tester user, define a role (Developer, Member and Tester), tags and optional message.


                                                                   Figure 26

  41. After filling in all the details, click on save button to invite the user.

  42. After clicking on save button, that user will get an invitation email and steps to get started with Hockey App and start testing our application.

Conclusion

In this article, we talked about how to integrate Hockey app in Xamarin Android application. I hope you enjoyed reading the article. Please comment to give feedback.