Payment gateway integration in Xamarin Form .Net MAUI using RazorPay

Brief: In this post we can see how to integrate payment gateway using RazorPay in Xamarin form for iOS and Android.


Right now i'm seeing very limited support for Xamarin with payment SDK from the top payment gateway providers like Stripe,RazorPay,PayU,JustPay. Few are providing the SDK but that is outdated and not supporting in the latest version. 

StartActivityForResult | OnActivityResult Deprecated in Xamarin Android

Along with androidX support StartActivityForResult and OnActivityResult got dprecated inside Fragment. Here we can see the one of the alternate approach for this deprecated api's in xamarin android.

Below code snippet explains the handling the above mentioned deprecated API's:

Android Keystore based Encryption and Decryption in Xamarin Android

Brief Walkthrough on Android Keystore based app security in Xamarin android

Data security should be considered as  top priority in any application and this is not just for password any sensitive data, app internal files including the database file. Any security breach in app secret data or app unique concepts(USP) can make way to competitors/attackers.  There are plenty of approaches one can choose to secure app private data.

Why Android Keystore based security : In general in any data encryption/decryption we need to provide the public/private keys. here the challenge is how we can secure these keys. Keystore based security provides solution for this issue where it generates and maintains the key dynamically. 

Dependency injection in xamarin form using AutoFac

Brief: Here we will learn how to add constructor Dependency Injection in xamarin.form using AutoFac

What is Dependency injection?
Before getting into any definition let us look into a simple example, For xamarin form application
whenever we need to get the native functionalities ( Check internet connectivity, Location,Camera
and any device details etc) Dependency injection is the best way to get the solution.

In below example shown how to launch phone dialer from xamarin form project. 

ReOrder the list items by drag and drop in xamarin android using RecyclerView

Brief:  Explanation with simple steps to how to re-order the list items by long press, drag and drop using recycler view in xamarin android.

Image Gallery Control using Xamarin Form

Brief: Implementation of Custom gallery control for Xamarin Form explained in a simple steps.

Description: If you have a plan to display image in gallery or in grid format for your Xamarin.Form application then you are in right place now.
You should be able to do so in next 15-20 minutes :). This implementation targets both android and iOS. Now quickly go through with steps.

Bug : Java.Lang.NullPointerException,Attempt to invoke virtual method 'boolean' on a null object reference

I have observed this above mentioned bug keeps on hitting when using Xamarin form,UI control "Frame" for android while it executes without any issues for iOS. 

In my previous post discussed about Frame border highlight issues in android. Frame control still has one or other problem with android and still remains a question mark why Xamarin team has not given any fix for this android specific problem.

How to fetch android sqlite db file from device in Mac Xamarin/Visul Studio.

Here i'm going to share one of the simple method to fetch sqlite database file from android device for xamarin or visul studio installed in mac machine. 
Recently when i was checking data stored in the sqlite db from android device, i couldn't do it easily as i fail to run ADB commands from my terminal.

Same if you are fetching DB file from Emulator it is pretty straight forward. 
Launch Device Monitor(Tools-> Device Monitor) 
select Emulator from left pane
select File Explorer from right pane 
Navigate to app data base file-> /data/data/com.appName.MyApp/databases/
Select required database file->"Pull a file from device" option from top right as shown in screen
Copy DB file to machine storage and open using sqlite db browser(

To fetch DB from android device using Windows machine we can use the following ADB command

Force Landscape or Portrait for a single page in Xamarin Form.

Device screen orientation in xamarin is usually configured from Host(Android/iOS) project as suggested here . But what if i need to change the screen orientation of one particular screen(say to landscape) in xamarin form and other screens are different (may be portrait), to do so there is no direct options available from xamarin form.
We will do the configuration in host project for the common screen orientation required throughout the application, to do any changes for particular screen need to touch back to the host project settings again because as of now there is no wrapper Form level API’s available. 

For example consider the scenario that my Form project contains the Five screens out of that, for Third screen i need give support for both Portrait and Landscape and for all other remaining screen only in portrait. This can be done in android as follows,

Use the MessageCenter class to send the message from the Form screen for which orientation need to be changed and receive the same from Android MainActivity class.

  public partial class ThirdPage : ContentPage
        protected override void OnAppearing()
           MessagingCenter.Send(this, "allowLandScapePortrait”);
         //during page close setting back to portrait
        protected override void OnDisappearing()
            MessagingCenter.Send(this, "preventLandScape");

Platform specific UI changes in Xamarin.Form

Brief: Walkthrough on the options available in xamarin form for changing UI element behaviour for specific platform.

Description: Xamarin form wrapper UI controls when it renders in each platform shows the native look and feel but still there are some quirks that has to be worked around to get the UI perfection.

For example if i add one label in my xamal page and on run in android and iOS shows the below output:
<?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="" xmlns:x="" xmlns:local="clr-namespace:CodeLog" x:Class="CodeLog.CodeLogPage">
<RelativeLayout HorizontalOptions="FillAndExpand"  >
    <Label Text="Code Log" 
   HorizontalOptions="FillAndExpand" />  
In iOS label has been overlapped with toolbar. So alone for iOS we need add To padding(Tool bar height 20px).

This kind of changes for particular platform can be achieved by using the below mentioned approaches without using the Custom renderer.

1.Using a generic class OnPlatform
3.Bindable Native Views in Xamal page (
4.customisation with effects(
In this article i will be making use of the OnPlatform for different UI control properties. From Xamarin.Forms version 2.3.4, Device.OnPlatform API has been deprecated with OnPlatform and On APIs.
 <?xml version="1.0" encoding="utf-8"?>
<ContentPage xmlns="" xmlns:x="" xmlns:local="clr-namespace:CodeLog" x:Class="CodeLog.CodeLogPage">
<RelativeLayout HorizontalOptions="FillAndExpand"  >
    <OnPlatform x:TypeArguments="Thickness">
      <On Platform="iOS" Value="0,20,0,0" />
      <On Platform="Android, WinPhone, Windows" Value="0,0,0,0" />
    <Label Text="Code Log" FontSize="25" FontFamily="Roboto-Bold" HorizontalTextAlignment="Center" 
  HorizontalOptions="FillAndExpand" />  
Platform specific Text color:
 <Label Text="Code Log" FontSize="18" FontAttributes="Bold"  FontFamily="Roboto-Bold" XAlign="Center"  HorizontalTextAlignment="Center" 
 RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}"> 
    <OnPlatform x:TypeArguments="Color" iOS="Red" Android="Blue"  />

ResolveLibraryProjectImport task failed unexpectedly in release mode in xamarin

This above mentioned error i got during my xamarin form project deployment in release mode. 
In my solution i have more then one project and this error indicates that linking between these project has been broken. If you are facing the same issue, then here i have listed out few scenarios that could help you to solve this issue:

1. Select the project in which error is pointing and Check the reference of other project and package. Reference with yellow triangle icon shows the broken reference. just delete it and re-add.
For any other project reference included in the current project, delete the current project reference and add the new one from release folder of that respective project.
Open "Configuration manager"

Error retrieving parent for item: No resource found that matches the given name...

This is the one of the frequent error we will get during Xamarin android/Form development. Here i have posted the resolution steps for this error in both windows and Mac machines:

Xamarin Form Frame outline color display issue in android

This is the quick glance on the issue i have faced during the use of Frame control in Xamarin form project and sharing here hoping that may helpful to somebody with the same issue.

Using Xamarin form Frame controls shows some strange behaviour in android platform where as it shows elegant look in iOS.
We can notice this difference in below screenshot.[Nexus S (KitKat) and Simulator iPhone6 iOS9.3]