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.

15 thoughts on “Getting Started with Twitter Fabric – Digits in Xamarin.Android”

  1. Have this issue:

    Duplicate Java type found! Mappings between managed types and Java types must be unique. First Type: ‘IO.Fabric.Sdk.Android.Services.Events.IEventsStorageListenerImplementor, Fabric, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’; Second Type: ‘Bindings.FabricSdk.Services.Events.IEventsStorageListenerImplementor, FabricSdk.Platform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’ Fabric Demo

  2. I’m getting deployment error when I use AppCompatActivity instead Activity. My question is Why I can’t use the AppCompatActivity.?

  3. Hello, im using xamarin digits in my projet, one error is appear when invoke new Digits

    Fabric.With(this, new TwitterCore(authConfig), new Digits());

    /Users/jefferson/Projects/investeapp31/investeapp31/MainActivity.cs(60,60): Error CS1540: Cannot access protected member Bindings.DigitsKit.Digits.Digits(System.IntPtr, Android.Runtime.JniHandleOwnership)’ via a qualifier of typeBindings.DigitsKit.Digits’. The qualifier must be of type `investeapp31.MainActivity’ or derived from it (CS1540) (investeapp31)

  4. This is My Code and following will be the Errors:

    protected override void OnCreate (Bundle bundle)
    {
    base.OnCreate (bundle);
    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.With(this, new TwitterCore(authConfig), new Digits());
    // Set our view from the “main” layout resource
    SetContentView (Resource.Layout.Main);

    // Get our button from the layout resource,
    // and attach an event to it
    DigitsAuthButton digitsButton = (DigitsAuthButton)FindViewById(Resource.Id.auth_button);

    digitsButton.Text = “Hey Authenticate Me”;
    digitsButton.SetCallback(this);
    digitsButton.Click += delegate {
    Digits.Authenticate(this);
    };
    }
    The errors I get is.
    Error:
    1. ‘Digits’ does not contain a constructor that takes 0 arguments
    2. Argument 1: cannot convert from ‘BlankApp1.Droid.MainActivity’ to ‘Bindings.DigitsKit.AuthConfig’ BlankApp1.Droid

  5. hi hello dear im using your way for fabric.Digits (xamarin.android) >
    in debug mode enything is ok and i recieved confirm sms messages
    but
    in relse mode at enter phone number screen after click send code tooltipe that try agine.
    i cont find probelm
    just in relase mode not work
    plase help me and send answer to my email
    i.entersoft@gmail.com
    mehdi golzari
    thanks for time

  6. i cant use following after added Digits

    Fabric.With(this, new TwitterCore(authConfig), new DigitsKit.Digits());

    And using Bindings.FabricSdk is not avail Digits after install from
    ManageNugetPackage

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.