using Android.App; using Android.Content; using Android.Content.PM; using Android.OS; using Android.Views; using System.Diagnostics; namespace Neighbourhood.omg.lol { [Activity(Exported = true, Theme = "@style/Maui.SplashTheme", LaunchMode = LaunchMode.SingleTop, MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] [IntentFilter([Intent.ActionSend], Categories = [Intent.CategoryDefault], DataMimeType = "text/plain")] [IntentFilter([Intent.ActionSend], Categories = [Intent.CategoryDefault], DataMimeType = "*/*")] public class MainActivity : MauiAppCompatActivity { protected override void OnCreate(Bundle? savedInstanceState) { base.OnCreate(savedInstanceState); // In case the app was opened (on first load) with an `ActionView` intent OnNewIntent(this.Intent); } protected override void OnNewIntent(Intent? intent) { base.OnNewIntent(intent); if (intent != null && intent.Type != null) { if (intent.Type.StartsWith("text/")) //string { string? subject = intent.GetStringExtra(Intent.ExtraSubject); string? shareString = intent.GetStringExtra(Intent.ExtraText); if (!string.IsNullOrWhiteSpace(shareString)) { State state = IPlatformApplication.Current!.Services.GetService()!; state.ShareStringSubject = subject; state.ShareString = shareString; } } else if (intent.Type.StartsWith("image/")) //image { string? shareString = intent.GetStringExtra(Intent.ExtraText); Java.Lang.Object? extra; if (OperatingSystem.IsAndroidVersionAtLeast(33)) extra = intent.GetParcelableExtra(Intent.ExtraStream, Java.Lang.Class.FromType(typeof(Android.Net.Uri))); else extra = intent.GetParcelableExtra(Intent.ExtraStream); if (extra is Android.Net.Uri) { Stream? stream = ContentResolver?.OpenInputStream((Android.Net.Uri)extra); byte[] bytes = new byte[stream?.Length ?? 0]; stream?.Read(bytes, 0, bytes.Length); string base64String = Convert.ToBase64String(bytes); if (!string.IsNullOrWhiteSpace(base64String)) { State state = IPlatformApplication.Current!.Services.GetService()!; state.SharePhotoContentType = intent.Type; state.SharePhotoSize = bytes.Length; state.SharePhotoText = shareString; state.SharePhoto = base64String; } } } else if (intent.Type.Equals(Intent.ActionSendMultiple)) //Multiple files { // TODO: we don't really support this at the moment. //System.Collections.IList? uriList; //if (OperatingSystem.IsAndroidVersionAtLeast(33)) // uriList = intent.GetParcelableArrayListExtra(Intent.ExtraStream, Java.Lang.Class.FromType(typeof(Android.Net.Uri))); //else uriList = intent.GetParcelableArrayListExtra(Intent.ExtraStream); } } } } }