Xamarin Android - Working With Xamarin Insights

Introduction

Xamarin Insights is used for using analytics and crash reporting for Xamarin. For more details, you can click here.

Let’s start

Before starting an Android application, we need to register the Xamarin Insights dashboard new app.

Step 1

Goto https://insights.xamarin.com/. Now, click New App button. Open New Window.

Step 2

In the new window, enter new app's name. Click "Create new app" button. Afterwards, the system generates new API key. This key uses Android app, so copy the API key value.

API key

Step 3

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

Select Blank App. Give your project a name and assign the project location.

 

Step 4

Go to Solution Explorer-> Project Name-> References. Right click on "Manage NuGet Packages" and open new dialog box. This dialog box is required to search Xamarin Insights, followed by installing Xamarin.Insights Packages.

 

Step 5

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

using Xamarin;

Step 6

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

 

C# Code 

  1. namespace XamarinInsights {  
  2.     [Activity(Label = "XamarinInsights", MainLauncher = true, Icon = "@drawable/icon")]  
  3.     public class MainActivity: Activity {  
  4.         Context context;  
  5.         protected override void OnCreate(Bundle bundle) {  
  6.             base.OnCreate(bundle);  
  7.             SetContentView(Resource.Layout.Main);  
  8.             Insights.Initialize("API_KEY"this);  
  9.         }  
  10.     }  

Step 7

Now, implement exceptions result in Xamarin Insights.

 
C# Code 
  1. try {  
  2.     Toast.MakeText(context, "Test", ToastLength.Short).Show();  
  3. catch (System.Exception error) {  
  4.     Insights.Report(error);  
  5. }  

Step 8

Now, implement the Exceptions result with the user data in Insights.

 
C# Code 
  1. try {  
  2.     Toast.MakeText(context, "Test", ToastLength.Short).Show();  
  3. catch (System.Exception error) {  
  4.     var UserInfo = new Dictionary < string,  
  5.         string > {  
  6.             {  
  7.                 "Email",  
  8.                 "[email protected]"  
  9.             },  
  10.             {  
  11.                 "Name",  
  12.                 "Anbu Mani"  
  13.             }  
  14.         };  
  15.     Insights.Report(error);  
  16.     Insights.Identify("USER001", UserInfo);  
  17. // This is just a sample script. Paste your real code (javascript or HTML) here.  
  18. if ('this_is' == /an_example/) {  
  19.     of_beautifier();  
  20. else {  
  21.     var a = b ? (c % d) : e[f];  
  22. }   

Step 9

Press F5 or build and run the application. Check the Xamarin.Insights dashboard.

 

Step 10

Go to Xamarin.Insights dashboard and we will see the exception log. In this log, we can get particular user information once this error is fixed. Afterwards, change the status to open/close.
 
Finally, we have successfully created Android app using Xamarin Insights.

Up Next
    Ebook Download
    View all
    Learn
    View all