I have a working app which I am now enhancing it by making it a Sharing Target. Consider that I am sending a simple text data such as a website link to my app. For this, I have added an Intent Filter as shown in the code below.
Everything works as expected except that when my app is launched by an external app (app acting as a Sharing Target) the Splash Screen is not shown and instead a blank page is shown. This makes sense because the Splash Screen is defined for the Main Activity and not for the Intent Filter.
My question is, therefore, how can I add a Splash Screen (or something equivalent like an animation) when my app is launched as Sharing Target?
I just want to improve on the dull blank page to a better UX,
[Activity( Label = "@string/app_name",
Exported = true,
Icon = "@mipmap/appicon",
Theme = "@style/Maui.SplashTheme",
MainLauncher = true,
LaunchMode = LaunchMode.SingleTask,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density, ScreenOrientation = ScreenOrientation.FullSensor)]
[IntentFilter([Intent.ActionSend], Categories = [Intent.CategoryDefault], Label = "@string/send_link", DataMimeTypes = ["text/plain"])]
public partial class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
Intent intent = this.Intent;
if (Intent.ActionSend.Equals(intent.Action) && intent.Type != null)
{
if ("text/plain".Equals(intent.Type))
{
string sharedText = intent.GetStringExtra(Intent.ExtraText);
if(sharedText is not null)
{
// use text data as required
}
}
}
}
}
// When app is a Sharing Target after it is launched
protected override async void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
string action = intent.Action;
string type = intent.Type;
if (Intent.ActionSend.Equals(intent.Action) && intent.Type != null)
{
if ("text/plain".Equals(intent.Type))
{
string sharedText = intent.GetStringExtra(Intent.ExtraText);
if (sharedText is not null)
{
// use text data as required
}
}
}
}