2024-06-14 07:20:04 +00:00
|
|
|
|
|
|
|
|
|
using Android.App;
|
|
|
|
|
using Android.Content;
|
2024-05-30 01:06:08 +00:00
|
|
|
|
using Android.Content.PM;
|
|
|
|
|
using Android.OS;
|
2024-07-02 00:01:06 +00:00
|
|
|
|
using Android.Views;
|
|
|
|
|
using System.Diagnostics;
|
2024-05-30 01:06:08 +00:00
|
|
|
|
|
|
|
|
|
namespace Neighbourhood.omg.lol {
|
2024-06-24 00:41:27 +00:00
|
|
|
|
[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)]
|
2024-06-14 07:20:04 +00:00
|
|
|
|
[IntentFilter([Intent.ActionSend], Categories = [Intent.CategoryDefault], DataMimeType = "text/plain")]
|
|
|
|
|
[IntentFilter([Intent.ActionSend], Categories = [Intent.CategoryDefault], DataMimeType = "*/*")]
|
2024-05-30 01:06:08 +00:00
|
|
|
|
public class MainActivity : MauiAppCompatActivity {
|
2024-06-14 07:20:04 +00:00
|
|
|
|
|
2024-07-02 00:01:06 +00:00
|
|
|
|
protected override void OnCreate(Bundle? savedInstanceState) {
|
2024-06-14 07:20:04 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-06-18 06:23:03 +00:00
|
|
|
|
string? subject = intent.GetStringExtra(Intent.ExtraSubject);
|
2024-06-14 07:20:04 +00:00
|
|
|
|
string? shareString = intent.GetStringExtra(Intent.ExtraText);
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(shareString)) {
|
|
|
|
|
State state = IPlatformApplication.Current!.Services.GetService<State>()!;
|
2024-06-18 06:23:03 +00:00
|
|
|
|
state.ShareStringSubject = subject;
|
2024-06-14 07:20:04 +00:00
|
|
|
|
state.ShareString = shareString;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (intent.Type.StartsWith("image/")) //image
|
|
|
|
|
{
|
2024-06-18 06:23:03 +00:00
|
|
|
|
string? shareString = intent.GetStringExtra(Intent.ExtraText);
|
2024-07-02 00:01:06 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2024-06-18 06:23:03 +00:00
|
|
|
|
if (extra is Android.Net.Uri) {
|
2024-07-02 00:01:06 +00:00
|
|
|
|
Stream? stream = ContentResolver?.OpenInputStream((Android.Net.Uri)extra);
|
2024-06-18 06:23:03 +00:00
|
|
|
|
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>()!;
|
|
|
|
|
state.SharePhotoContentType = intent.Type;
|
|
|
|
|
state.SharePhotoSize = bytes.Length;
|
|
|
|
|
state.SharePhotoText = shareString;
|
|
|
|
|
state.SharePhoto = base64String;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-14 07:20:04 +00:00
|
|
|
|
}
|
2024-07-02 00:01:06 +00:00
|
|
|
|
else if (intent.Type.Equals(Intent.ActionSendMultiple)) //Multiple files
|
2024-06-14 07:20:04 +00:00
|
|
|
|
{
|
2024-07-02 00:01:06 +00:00
|
|
|
|
// 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);
|
2024-06-14 07:20:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-30 01:06:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|