Xamarin Android - Working With Xamarin HockeyApp

Introduction

HockeyApp is used get crash reports, events and feedback from the users. Its used for testers and analyzing our Applications. For more details, you can click here.

Let’s start

Prior to starting an Android Application, we need to register HockeyApp dashboard new app.

Step 1

Go to http://hockeyapp.net/. Click New App button and open New Window.


Step 2

In the new Window, there are two options. The first one is to create a new app and the other one is for Uploading Build Items [Apk or Zip ], or creating new item manually. Check the last condition - “Don’t Want to upload a build? Create the app manually instead”.

Step 3

In the new window, select Platform, Release Type, and give Title for Application and Package. Click Save button. Afterwards, the system generates new App ID. This key uses Android app, so copy the App ID value.


Step 4

Open Visual Studio -> New Project -> Templates -> Visual C# -> Android -> Blank App.

Select Blank App. Give the Project Name and Project Location.

Step 5

Go to Solution Explorer-> Project Name-> References, followed by right click to Manage NuGet Packages. Open new Dialog box. This dialog box is required to search HockeySDK, followed by installing HockeySDK.Xamarin Packages.

Step 6

Open Solution Explorer-> Project Name-> Resources-> Layout-> Main.axml. Design the page for the Button Event Handler. Here, I created 3 buttons.

Step 7

Now, we need to initialize HockeyApp in MainActvity.cs and add the new namespace given below. 

  1. using HockeyApp.Android;  
  2. using HockeyApp.Android.Metrics;   

Step 8

Now, we need to declare the App ID variables.

  1. public const string HOCKEYAPP_APPID = "YOUR APP ID";  

 

Step 9

Open Solution Explorer-> Project Name-> MainActivity.cs. Click Open CS code page view, followed by adding namespaces given below.

C# code 

  1. protected override void OnCreate(Bundle bundle) {  
  2.     base.OnCreate(bundle);  
  3.     // Register  
  4.     CrashManager.Register(this, HOCKEYAPP_APPID);  
  5.     UpdateManager.Register(this, HOCKEYAPP_APPID);  
  6.     MetricsManager.Register(Application, HOCKEYAPP_APPID);  
  7.     SetContentView(Resource.Layout.Main);  
  8.     FindViewById < Button > (Resource.Id.BtnFeedback).Click += delegate {  
  9.         //Register with the feedback manager  
  10.         FeedbackManager.Register(this, HOCKEYAPP_APPID, null);  
  11.         //Show the feedback screen  
  12.         FeedbackManager.ShowFeedbackActivity(this);  
  13.     };  
  14.     FindViewById < Button > (Resource.Id.BtnCrash).Click += delegate {  
  15.         // Throw a deliberate sample crash  
  16.         throw new HockeyAppSampleException("You intentionally caused a crash!");  
  17.     };  
  18.     FindViewById < Button > (Resource.Id.BtnTrackEvent).Click += delegate {  
  19.         MetricsManager.TrackEvent("My custom event.");  
  20.     };  
  21. }  
  22. protected override void OnResume() {  
  23.     base.OnResume();  
  24.     //Start Tracking usage in this activity  
  25.     Tracking.StartUsage(this);  
  26. }  
  27. protected override void OnPause() {  
  28.     //Stop Tracking usage in this activity  
  29.     Tracking.StopUsage(this);  
  30.     base.OnPause();  
  31. }   

Step 10

Now, implement exceptions Class.



C# code
 
  1. public class HockeyAppSampleException: System.Exception {  
  2.     public HockeyAppSampleException(string msg): base(msg) {}  
  3. }  

Step 11

Press F5 or build and run the Application. Check the HockeyApp Dashboard.

Step 12

Go to HockeyApp dashboard and we will see the exception log, Events, and FeedBack. In this log, we can get particular user information, once the error is fixed. Afterwards, change the status to open/close.

Finally, we have successfully created Android app, using HockeyApp.

Up Next
    Ebook Download
    View all
    Learn
    View all