132 lines
4.9 KiB
C#
132 lines
4.9 KiB
C#
using Android.App;
|
|
using Android.Content;
|
|
using Android.Content.PM;
|
|
using Android.Runtime;
|
|
using Android.OS;
|
|
using Android.Net;
|
|
using Android.Provider;
|
|
using Android.Database;
|
|
|
|
namespace Billing.Droid
|
|
{
|
|
[Activity(
|
|
Label = "@string/applabel",
|
|
Icon = "@mipmap/icon",
|
|
RoundIcon = "@mipmap/icon_round",
|
|
Theme = "@style/MainTheme",
|
|
ScreenOrientation = ScreenOrientation.Portrait,
|
|
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
|
|
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
|
|
{
|
|
protected override void OnCreate(Bundle savedInstanceState)
|
|
{
|
|
base.OnCreate(savedInstanceState);
|
|
|
|
string url;
|
|
if (Intent.ActionView.Equals(Intent.Action) && Intent.Data is Uri uri)
|
|
{
|
|
if (uri.Authority == "org.tsanie.billing.shortcuts")
|
|
{
|
|
url = uri.Path;
|
|
}
|
|
else
|
|
{
|
|
url = GetFilePath(BaseContext, uri);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
url = null;
|
|
}
|
|
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
|
|
Xamarin.Forms.Forms.Init(this, savedInstanceState);
|
|
Xamarin.FormsMaps.Init(this, savedInstanceState);
|
|
LoadApplication(new App(url));
|
|
}
|
|
|
|
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
|
|
{
|
|
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
|
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
}
|
|
|
|
private string GetFilePath(Context context, Uri uri)
|
|
{
|
|
if (DocumentsContract.IsDocumentUri(context, uri))
|
|
{
|
|
Uri contentUri;
|
|
string[] split;
|
|
switch (uri.Authority)
|
|
{
|
|
case "com.android.externalstorage.documents":
|
|
split = DocumentsContract.GetDocumentId(uri).Split(':');
|
|
if (split[0] == "primary")
|
|
{
|
|
var external = ExternalCacheDir.Path;
|
|
external = external[..external.IndexOf("/Android/")];
|
|
return external + "/" + split[1];
|
|
}
|
|
break;
|
|
|
|
case "com.android.providers.downloads.documents":
|
|
contentUri = ContentUris.WithAppendedId(
|
|
Uri.Parse("content://downloads/public_downloads"),
|
|
long.Parse(DocumentsContract.GetDocumentId(uri)));
|
|
return GetDataColumn(context, contentUri, null, null);
|
|
|
|
case "com.android.providers.media.documents":
|
|
split = DocumentsContract.GetDocumentId(uri).Split(':');
|
|
contentUri = split[0] switch
|
|
{
|
|
"image" => MediaStore.Images.Media.ExternalContentUri,
|
|
"video" => MediaStore.Video.Media.ExternalContentUri,
|
|
"audio" => MediaStore.Audio.Media.ExternalContentUri,
|
|
_ => null
|
|
};
|
|
return GetDataColumn(context, contentUri, "_id=?", new[] { split[1] });
|
|
}
|
|
}
|
|
else if (uri.Scheme == "content")
|
|
{
|
|
if (uri.Authority == "com.speedsoftware.rootexplorer.fileprovider")
|
|
{
|
|
var path = uri.Path;
|
|
if (path.StartsWith("/root/"))
|
|
{
|
|
return path[5..];
|
|
}
|
|
return path;
|
|
}
|
|
return GetDataColumn(context, uri, null, null);
|
|
}
|
|
else if (uri.Scheme == "file")
|
|
{
|
|
return uri.Path;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private string GetDataColumn(Context context, Uri uri, string selection, string[] selectionArgs)
|
|
{
|
|
ICursor cursor = null;
|
|
try
|
|
{
|
|
cursor = context.ContentResolver.Query(uri, new[] { "_data" }, selection, selectionArgs, null);
|
|
if (cursor != null && cursor.MoveToFirst())
|
|
{
|
|
var index = cursor.GetColumnIndexOrThrow("_data");
|
|
return cursor.GetString(index);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (cursor != null)
|
|
{
|
|
cursor.Close();
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
} |