The ability to receive text and images from another app is a behavior that has become the norm on mobile apps.

In this article we'll look at how to activate the receipt of text data via Xamarin Android.

The first step is to change the activity statement for which the data will be received. In our example we will change the MainActivity But if you need it, you can create a dedicated business.

In the file MainActivity.cs the following use must be added:

using Android.Content;

This allows access to the Intent class. On the MainActivity class we add the attribute IntentFilter and we declare that we accept the actions
Send and SendMultiple :

[IntentFilter(
    new[] { Intent.ActionSend, Intent.ActionSendMultiple },
    Categories = new[] { Intent.CategoryBrowsable, Intent.CategoryDefault        },
 DataMimeType = "text/plain")]

Then to recover the text sent to your app is very simple:


   protected override void OnCreate(Bundle savedInstanceState)
    {

        base.OnCreate(savedInstanceState);
        // votre code ici
        // récupération du type
        var type = Intent.Type;

        // récupération de l'action
        var action = Intent.Action;
        if (Intent.ActionSend == action && Intent.Type != null)
        {
            if ("text/plain" == type)
            {
                string sharedText = Intent.GetStringExtra(Intent.ExtraText);
            }
        }
        else if (Intent.ActionSendMultiple == action && type != null)
        {
            if ("text/plain" == type)
            {
                string sharedText = Intent.GetStringExtra(Intent.ExtraText);
            }
        }
    }

Now when you share text your app is available in the list of text-accepting apps:

Original illustration unavailable

L’application is well in lists of applications accepting text sharing

Happy coding 🙂

To go further: