Skip to content

Commit 3197180

Browse files
Android Permissions cleanup (#202)
1 parent c9cef49 commit 3197180

File tree

2 files changed

+1
-50
lines changed

2 files changed

+1
-50
lines changed

Pixed.Android/MainActivity.cs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using Android.App;
2-
using Android.Content;
32
using Android.Content.PM;
43
using Android.OS;
5-
using Android.Runtime;
64
using Avalonia;
75
using Avalonia.Android;
86
using Avalonia.ReactiveUI;
@@ -11,7 +9,6 @@
119
using Pixed.Application.DependencyInjection;
1210
using Pixed.Application.IO;
1311
using Pixed.Application.Platform;
14-
using System.Threading.Tasks;
1512

1613
namespace Pixed.Android;
1714

@@ -22,8 +19,7 @@ namespace Pixed.Android;
2219
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.UiMode)]
2320
public class MainActivity : AvaloniaMainActivity<App>
2421
{
25-
private TaskCompletionSource<Permission> _permissionTcs;
26-
protected override async void OnCreate(Bundle? savedInstanceState)
22+
protected override void OnCreate(Bundle? savedInstanceState)
2723
{
2824
AndroidX.Core.SplashScreen.SplashScreen.InstallSplashScreen(this);
2925
PlatformSettings.MainActivity = this;
@@ -34,13 +30,6 @@ protected override async void OnCreate(Bundle? savedInstanceState)
3430
IPlatformSettings.Instance = new PlatformSettings();
3531

3632
base.OnCreate(savedInstanceState);
37-
var permissions = await CheckPermissions();
38-
39-
if (permissions != Permission.Granted)
40-
{
41-
Process.KillProcess(Process.MyPid());
42-
return;
43-
}
4433
}
4534
protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
4635
{
@@ -50,42 +39,5 @@ protected override AppBuilder CustomizeAppBuilder(AppBuilder builder)
5039
.UseReactiveUI()
5140
.UseShell();
5241
}
53-
54-
private Task<Permission> CheckPermissions()
55-
{
56-
if (Environment.IsExternalStorageManager)
57-
{
58-
return Task.FromResult(Permission.Granted);
59-
}
60-
61-
if (_permissionTcs != null && _permissionTcs.Task.IsCompleted)
62-
{
63-
_permissionTcs.SetCanceled();
64-
_permissionTcs = null;
65-
}
66-
67-
Intent intent = new(global::Android.Provider.Settings.ActionManageAppAllFilesAccessPermission);
68-
intent.AddCategory("android.intent.category.DEFAULT");
69-
intent.SetData(global::Android.Net.Uri.Parse("package:" + PackageName));
70-
StartActivityForResult(intent, 1);
71-
_permissionTcs = new TaskCompletionSource<Permission>();
72-
return _permissionTcs.Task;
73-
}
74-
75-
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent? data)
76-
{
77-
base.OnActivityResult(requestCode, resultCode, data);
78-
79-
if (requestCode == 1)
80-
{
81-
if (Environment.IsExternalStorageManager)
82-
{
83-
_permissionTcs.TrySetResult(Permission.Granted);
84-
return;
85-
}
86-
87-
_permissionTcs.TrySetResult(Permission.Denied);
88-
}
89-
}
9042
}
9143

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.nejman.pixed" android:versionCode="17" android:versionName="1.7">
33
<uses-permission android:name="android.permission.INTERNET" />
4-
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
54
<application android:label="Pixed" android:icon="@mipmap/pixed_icon" android:theme="@style/Theme.Splash" />
65
</manifest>

0 commit comments

Comments
 (0)