44 protected override void OnCreate(Bundle savedInstanceState) {
45 base.OnCreate(savedInstanceState);
46 Intent intent = Intent;
48 Toast.MakeText(
this, Resources?.GetString(
Resource.String.FileNotFound), ToastLength.Short)?.Show();
49 FinishAndRemoveTask();
53 if (intent.Action == Intent.ActionView) {
56 else if (intent.Action == Intent.ActionSend) {
57 if (Build.VERSION.SdkInt >= (BuildVersionCodes)33) {
58 uri = intent.GetParcelableExtra(Intent.ExtraStream, Java.Lang.Class.FromType(typeof(
Uri))) as
Uri;
61#pragma warning disable CA1422
62 uri = intent.GetParcelableExtra(Intent.ExtraStream) as
Uri;
63#pragma warning restore CA1422
67 Toast.MakeText(
this, Resources?.GetString(
Resource.String.FileNotFound), ToastLength.Short)?.Show();
68 FinishAndRemoveTask();
73 || fileStream ==
null) {
74 Toast.MakeText(
this, Resources?.GetString(
Resource.String.FileNotFound), ToastLength.Short)?.Show();
75 FinishAndRemoveTask();
96 new AlertDialog.Builder(
this).SetTitle(Resources?.GetString(
Resource.String.Import))
97 ?.SetMessage(
string.Format(Resources?.GetString(
Resource.String.InsureImporting)!, fileName))
99 Resources?.GetString(
Resource.String.Yes)!,
100 async void (_, _) => await
ImportFileAsync(fileName, fileSize, fileStream)
102 ?.SetNegativeButton(Resources?.GetString(
Resource.String.No)!, (_, _) => FinishAndRemoveTask())
106 new AlertDialog.Builder(
this).SetTitle(Resources?.GetString(
Resource.String.NotSupportedType))
107 ?.SetMessage(
string.Format(Resources?.GetString(
Resource.String.FileTypeIsNotSupported)!, extension))
108 ?.SetPositiveButton(Resources?.GetString(
Resource.String.Ok)!, (_, _) => FinishAndRemoveTask())
115 AlertDialog importingDialog =
null;
118 if (size > 10L * 1024 * 1024) {
119 RunOnUiThread(() => {
120 LinearLayout layout =
new(
this) { Orientation = Orientation.Vertical };
121 int margin = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 24, Resources?.DisplayMetrics);
122 layout.SetPadding(0, margin, 0, margin);
123 layout.SetGravity(GravityFlags.Center);
124 ProgressBar progressBar =
new(
this) { Indeterminate =
true };
125 layout.AddView(progressBar);
126 importingDialog =
new AlertDialog.Builder(
this).SetTitle(Resources?.GetString(
Resource.String.Importing))
128 ?.SetCancelable(
false)
133 await Task.Run(() => {
144 await stream.DisposeAsync();
145 RunOnUiThread(() => {
146 importingDialog?.Dismiss();
147 AlertDialog.Builder builder =
new AlertDialog.Builder(
this)
148 .SetTitle(Resources?.GetString(
Resource.String.ImportedSuccessfully))
150 Resources?.GetString(
Resource.String.Yes)!,
152 Intent intent = new(this, typeof(MainActivity));
153 intent.SetFlags(ActivityFlags.ReorderToFront);
154 StartActivity(intent);
155 FinishAndRemoveTask();
158 ?.SetNegativeButton(Resources?.GetString(
Resource.String.No)!, (_, _) => FinishAndRemoveTask());
159 builder?.SetMessage(Resources?.GetString(
Resource.String.InsureLaunchingGame));
164 catch (Exception e) {
165 RunOnUiThread(() => {
166 importingDialog?.Dismiss();
167 new AlertDialog.Builder(
this).SetTitle(Resources?.GetString(
Resource.String.FailedToImport))
168 ?.SetMessage(e.Message)
169 ?.SetPositiveButton(Resources?.GetString(
Resource.String.Ok)!, (_, _) => FinishAndRemoveTask())
180 Stream stream =
null;
182 using (ICursor cursor = ContentResolver?.Query(uri,
null,
null,
null,
null)) {
184 && cursor.MoveToFirst()) {
185 int nameIndex = cursor.GetColumnIndex(IOpenableColumns.DisplayName);
186 if (nameIndex >= 0) {
187 name = cursor.GetString(nameIndex);
189 int sizeIndex = cursor.GetColumnIndex(IOpenableColumns.Size);
190 if (sizeIndex >= 0) {
191 size = cursor.GetLong(sizeIndex);
195 stream = ContentResolver?.OpenInputStream(uri);
200 if (
string.IsNullOrEmpty(name)) {
201 name = Path.GetFileName(uri.Path);