Getting Started with Twitter Fabric – Digits in Xamarin.Android

Twitter have some awesome tools for saving developers time and boosting productivity. One such tool is Twitter Fabric. Fabric is a collection of tools like Crashlytics (Crash Reporting), Mobile Analytics, Digits and much more.

Sadly, their official SDK’s are not yet available for Xamarin, still, there is a Xamarin binding which works well. Thanks to Michel Moreira for this binding.

This binding is available as Nuget Package, so getting started with this plugin is so easy.

Steps to integrate Digits to your Xamarin.Android app.

Step 1: Get a Fabric Account (https://fabric.io)

Step 2: Sadly, for getting API Keys, you need Android studio. So make sure you have Android Studio Installed (just for the sake of API keys).

Step 3: In Android Studio, select Plugins-> Browse Repositories -> Search for Fabric Plugin, Install it, Restart the IDE.

Step 4: Start a Blank New Project with the name Intended for your Xamarin.Android project.

Step 5: Click on Fabric Icon in Android Studio, Login to Fabric with your account and select Digits from the kits listed.

Step 6: Create Digits Account, and get the API keys obtained from AndroidManifest.xml file and MainActivity.java.

Step 7: Build the project in Android Studio. Once the app is built from Android Studio, your app gets listed in Fabric Dashboard where you can customize the One Time Password message, and get all they API keys.

Step 8: Enough with Android Studio (make sure you copy the keys from AndroidManifest.xml and MainActivity.java

AndroidManifest.xml

<meta-data
android:name=”io.fabric.ApiKey”
android:value=”your-key-here”
/>

MainActivity.java

Step 9: Back to our awesome Xamarin, either in Visual Studio or Xamarin Studio. (I use VS)

Step 10: Open your project, Right Click your project in Solution Explorer and Select Manage Nuget Package.

Step 11: Search for Digits by Michel Moreira, and Install the package.

Step 12: Open your activity, in which you want Digits Authentication (in my case MainActivity.cs)

Step 13:  Paste the TWITTER_KEY and TWITTER_SECRET TO your MainActivity.cs

Also, paste the meta data information to AndroidManifest.xml under application node.

  <application android:label=”Fabric_Demo”>
<meta-data
android:name=”io.fabric.ApiKey”
android:value=”your-key-here”
/>
</application>

Step 14:  Initialize fabric in your OnCreate method.

Step 15: Inherit your MainActivity from  IAuthCallBack and implement the interface. (Which will add two methods namely Success and Failure to your Activity)

Step 16:  There are multiple ways to authenticate. You can theme your default button or have custom Authentication action from anywhere in the program.

Step 17: For example, you need to authenticate mobile number on a button click, just have  Digits.Authenticate(this);  in your button click event.

Step 18: If you want to have digits button, add

   <com.digits.sdk.android.DigitsAuthButton
android:id=”@+id/auth_button”
android:layout_width=”match_parent”
android:layout_height=”wrap_content” />

in your layout file.

and in your Main Activity, set the callback of the button to the current class.

Step 19: Handle Success and Failure methods. Success method will be called when your authentication using mobile number if verified and it will have the details in DigitsSession p0 variable or p1 gives the mobile number. Failure method will be called if the number cannot be authenticated or User cancels the process.

Step 20: Run and see it in action.

Skip Step 1 to 10 by requesting Twitter Fabrics team a Xamairn plugin 🙂 https://twitter.com/fabric

Shout out your suggestions, feedback and doubts in comment section below.

The Fabric Demo Solution can be downloaded from my Github

Credits: Michel Moreira‘s Fabric Binding for Xamarin.