-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.NET MAUI does not work with Android 13 Android.permission.write_external_storage #11275
Comments
@FatCodeMonkey does it work if you add android:requestLegacyExternalStorage="true" to your manifest? |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
What baffles me, is that .net MAUI was released with an initial target Android API of 33. But the underlying code does not support Android API 33! Starting from Android 13, if your application target SDK is specified to 33 or above, the READ_EXTERNAL_STORAGE permission will be completely useless, and applying for it will have no effect. Correspondingly, Google has added three runtime permissions: READ_MEDIA_IMAGES, READ_MEDIA_VIDEO, and READ_MEDIA_AUDIO, which are used to manage the photos, videos and audio files of the phone respectively. That is to say, in the past, you only needed to apply for a READ_EXTERNAL_STORAGE permission. This is no longer possible. You have to apply for it on demand, so that users can learn more precisely which media permissions your app has applied for.
It is the same for notifications!
I pulled the Android permissions code, and updated it to support API 33. Hopefully they will realize that making the "Essentials" an actual part of the MAUI core, requires a higher level of attention to external API changes. |
@Stedy59 Could you share your modifications while we wait for the MAUI team to fix this ? (right now as a workaround I fixed the target android sdk to 30 in the android manifest). |
I do not see how I can circumvent the issue either. Everyone around me has devices with the latest Android installed which I can't run my .net maui app on. The app can't work without media picker (MediaPicker control), but it seems to rely on WRITE_EXTERNAL_STORAGE only, which is not in the list of android permissions anymore. It does not care about new api 33 permissions like READ_MEDIA_IMAGES, it wants WRITE_EXTERNAL_STORAGE and does not run camera without it. Am I stuck till the issue is fixed in new ver of .net maui core, or there is some temp. workaround for that? |
@YMichurin Unless you need what api 33 need, change the target SDK inside the android manifest to target api level 32. That did it for me |
hi @sidewinder94, if I do change the manifest to api 32 and let's say I do not use api 33 features, would my app work on a phone with the newest api 33 installed? |
Here is a snippet that I use to open the device gallery and/or select a ringtone... [assembly: UsesPermission(Name = "android.permission.READ_EXTERNAL_STORAGE", MaxSdkVersion = 32)]
[assembly: UsesPermission(Name = "android.permission.READ_MEDIA_AUDIO")]
[assembly: UsesPermission(Name = "android.permission.READ_MEDIA_IMAGES")]
[assembly: UsesPermission(Name = "android.permission.READ_MEDIA_VIDEO")]
namespace StedySoft.Shared {
#region Class MediaServices
public static partial class MediaServices {
#region Declarations
internal const int OPENGALLERY = 100;
internal const int OPENRINGTONES = 101;
#endregion
#region Private Methods
private static bool PlatformGetExternalStoragePermissions(string requestMessage, int permissionType = OPENGALLERY) {
try {
Permission status = Permission.Denied;
if (Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu) {
switch (permissionType) {
case OPENGALLERY:
status = ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.ReadMediaImages);
break;
case OPENRINGTONES:
status = ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.ReadMediaAudio);
break;
}
}
else {
status = ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.ReadExternalStorage);
}
if (status != Permission.Granted) {
if (Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu) {
switch (permissionType) {
case OPENGALLERY:
if (ActivityCompat.ShouldShowRequestPermissionRationale(Platform.Activity, Manifest.Permission.ReadMediaImages)) { Toast.Show(requestMessage, ToastDuration.Long); }
ActivityCompat.RequestPermissions(Platform.Activity, new[] { Manifest.Permission.ReadMediaImages }, 0);
break;
case OPENRINGTONES:
if (ActivityCompat.ShouldShowRequestPermissionRationale(Platform.Activity, Manifest.Permission.ReadMediaAudio)) { Toast.Show(requestMessage, ToastDuration.Long); }
ActivityCompat.RequestPermissions(Platform.Activity, new[] { Manifest.Permission.ReadMediaAudio }, 0);
break;
}
}
else {
if (ActivityCompat.ShouldShowRequestPermissionRationale(Platform.Activity, Manifest.Permission.ReadExternalStorage)) { Toast.Show(requestMessage, ToastDuration.Long); }
ActivityCompat.RequestPermissions(Platform.Activity, new[] { Manifest.Permission.ReadExternalStorage }, 0);
}
Stopwatch stopwatch = new();
stopwatch.Start();
do {
Thread.Sleep(10);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Tiramisu) {
switch (permissionType) {
case OPENGALLERY:
status = ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.ReadMediaImages);
break;
case OPENRINGTONES:
status = ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.ReadMediaAudio);
break;
}
}
else {
status = ContextCompat.CheckSelfPermission(Application.Context, Manifest.Permission.ReadExternalStorage);
}
if (stopwatch.ElapsedMilliseconds > 10000) {
throw new Exception("Timed out waiting for permission.");
}
} while (status != Permission.Granted);
}
return true;
}
catch (Exception ex) {
Logger.LogException("MediaServices", "PlatformGetExternalStoragePermissions", ex);
}
return false;
} |
@YMichurin Yes, no issues there, since devices running higher versions know how to deal with older ones. |
And here is the code
|
Same here. |
I have the same issue. The question now is, how long will it take for them to release an update to fix this. Releasing updates seems to be taking a really long time. |
I avoided this issue by using Xamarin.MediaGallery instead. https://github.com/dimonovdd/Xamarin.MediaGallery |
I tried this, and followed the readme file, with both the stable and preview release, but it just pops up a dialog saying "Can't connect to the camera" in the Android 13 Emulator with SDK level 33. Are you on .NET6 like the sample? Is there some other trick to it? |
@symbiogenesis, again, if you don't need to target sdk33 just target 32 and it'll work just fine. Still a bug that needs to be fixed. |
Thank you. I had tried this before and it didn't work for some reason, but I tried it now and it works. This is the best solution. |
I'm having the same problem. I'm following the colleague's last suggestion, that is, changing the destination to sdk 32. |
After you update your app to target Android 11, the system ignores the requestLegacyExternalStorage flag. [source] So no, that's a completely different option that only worked before Android 11. |
How do you get that to work? If I do that I get:
@espenrl The compilation still happens with API 33 and the MediaPicker.Capture methods won't work. Because the warning mentions $(TargetFrameworkVersion), I tried adding a |
Double check that Targeting Android option is on in the project settings and it targets lower version. This is what I have in the project file and it works. I do not think you need anything else behind that to avoid the error
|
Hmm… yes, that option is already in our csproj file, it's needed to build Android. This sets the minSdkVersion. |
I just ignored the XA4211 warning. It worked. I took photos successfully on Android 13, both with the real device and the emulator. I think your PR is still very helpful, and I hope you continue to clean up that horrible code. The iOS code is possibly even worse. The photos don't respect the device orientation, and it is using obsolete APIs with lots of TODOs and pragmas in the code. |
Today we have .net 7.0.4 is this solved in this release ?
Am Mi., 15. März 2023 um 14:39 Uhr schrieb Gijsbert ter Horst <
***@***.***>:
… @guillaumelimoo <https://github.com/guillaumelimoo> Is that targeting
actually causing problems? Because it doesn't cause me any problems. Note
that as the error says, ACW compilation still uses API-33. I'm not sure
what ACW compilation is, apparently to an extent it still uses API 33. In
my case I avoid the issues caused by the permissions, yet ZXing still works
properly. The relevant section of my AndroidManifest.xml was shown
earlier in the thread. I had some issues myself getting the configuration
right. In my case I had to ensure there was no maxSdkVersion in <uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />. I thought
this was counter-intuitive, but it I think it is because of that ACW
compilation thing.
—
Reply to this email directly, view it on GitHub
<#11275 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AISUTQG4KCWTA6X4CLY5HNLW4HBADANCNFSM6AAAAAAR5DB6KM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
No, this is a MAUI problem, not a .NET problem. We're waiting for the next .NET MAUI 7.0 service release. |
Ok and the date is ? |
Unknown. It's running late. Maybe because of the upcoming .NET MAUI 8
release.
…On Wed, 15 Mar 2023, 18:11 AHComp, ***@***.***> wrote:
Ok and the date is ?
—
Reply to this email directly, view it on GitHub
<#11275 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJFPZPKF2PAAFRY52F4J33W4HZ5ZANCNFSM6AAAAAAR5DB6KM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
It's Visual Studio 2022 I'm using. Getting to the exact same point as @AHComp. Have tried many different versions of target SDK in the app manifest and project code, all result in Using API-33 for ACW Compliance |
It works fine. We're using this in our production app.
…On Wed, 15 Mar 2023, 20:29 Fabian Pruntsch, ***@***.***> wrote:
I am not debugging on a emulator but on a real device that uses Android
13.0 - API 33. Would it still help to downgrade the target SDK or am i
doomed because the phone has API 33 ?
—
Reply to this email directly, view it on GitHub
<#11275 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJFPZIJ7K5YLE7J5EC4PJDW4IJ77ANCNFSM6AAAAAAR5DB6KM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Google Play has now policy that before August 31 2023, all new apps must target API 33. Quoted from mail from Google Play: Starting August 31, 2023:New apps and app updates must target API level 33 to be submitted to Google Play (Wear OS must target API 30). Existing apps must target API level 31 or above to remain discoverable by all users on Google Play. Apps that target API level 30 or below (target API level 29 or below for Wear OS), will only be discoverable on devices running Android OS same or lower than your apps’ target API level. |
@Redth How long it could take to add the service release for .Net 7 to visual studio ? |
This has nothing to do with Visual Studio. When .NET MAUI 7 service release
is released, it should include the fix. You can install that update. It is
possible that Visual Studio has a menu that performs the action for you,
you can also use the .NET CLI. Or you could manually download the new
version and replace the old version on your filesystem.
My point is. Don't look for a solution in the wrong place. MAUI is its own
thing.
…On Wed, 22 Mar 2023, 14:35 AHComp, ***@***.***> wrote:
@Redth <https://github.com/Redth> How long it could take to add the
service release for .Net 7 to visual studio ?
—
Reply to this email directly, view it on GitHub
<#11275 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJFPZL5SS6JBGYU6GDC72DW5L5ZNANCNFSM6AAAAAAR5DB6KM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Also it is separate from the .NET service release. Unless the MAUI service
release is dependent on fixes in .NET. Then a .NET service release must
first be released, before a MAUI service release can be made. I don't
expect that to be the case.
…On Wed, 22 Mar 2023, 16:08 Gijsbert ter Horst, ***@***.***> wrote:
This has nothing to do with Visual Studio. When .NET MAUI 7 service
release is released, it should include the fix. You can install that
update. It is possible that Visual Studio has a menu that performs the
action for you, you can also use the .NET CLI. Or you could manually
download the new version and replace the old version on your filesystem.
My point is. Don't look for a solution in the wrong place. MAUI is its own
thing.
On Wed, 22 Mar 2023, 14:35 AHComp, ***@***.***> wrote:
> @Redth <https://github.com/Redth> How long it could take to add the
> service release for .Net 7 to visual studio ?
>
> —
> Reply to this email directly, view it on GitHub
> <#11275 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAJFPZL5SS6JBGYU6GDC72DW5L5ZNANCNFSM6AAAAAAR5DB6KM>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>
|
It has 100 % to do with Visual Studio because MAUI "workfload" is installed/updated when installing/updating Visual Studio. |
My point being that you _may_ do that. But MAUI is a tool completely
separate from Visual Studio and does not _need_ to wait on anything related
to Visual Studio.
In fact I suspect that MAUI isn't even installed by Visual Studio, but by
the Visual Studio installer, which is another tool altogether.
I have been using MAUI for several months now, yet I haven't touched Visual
Studio in years.
Using Visual Studio for MAUI is like having a garage attached to your home.
MAUI is the car. Sure it is convenient to park your car in the garage.
However, you don't need a garage to park your car. You also in general
don't need to renovate your garage if you buy a new car. They're two
separate things, that are sometimes nice to use together.
…On Wed, 22 Mar 2023, 16:30 janseris, ***@***.***> wrote:
This has nothing to do with Visual Studio. When .NET MAUI 7 service
release is released, it should include the fix. You can install that
update. It is possible that Visual Studio has a menu that performs the
action for you, you can also use the .NET CLI. Or you could manually
download the new version and replace the old version on your filesystem. My
point is. Don't look for a solution in the wrong place. MAUI is its own
thing.
… <#m_-107866908537372821_>
On Wed, 22 Mar 2023, 14:35 AHComp, *@*.*> wrote: @Redth
<https://github.com/Redth> https://github.com/Redth
<https://github.com/Redth> How long it could take to add the service
release for .Net 7 to visual studio ? — Reply to this email directly, view
it on GitHub <#11275 (comment)
<#11275 (comment)>>, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AAJFPZL5SS6JBGYU6GDC72DW5L5ZNANCNFSM6AAAAAAR5DB6KM
<https://github.com/notifications/unsubscribe-auth/AAJFPZL5SS6JBGYU6GDC72DW5L5ZNANCNFSM6AAAAAAR5DB6KM>
. You are receiving this because you commented.Message ID: @.*>
It has 100 % to do with Visual Studio because MAUI is installed via Visual
Studio update.
—
Reply to this email directly, view it on GitHub
<#11275 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJFPZJWBOWEOLSPLNLTRPDW5MLH5ANCNFSM6AAAAAAR5DB6KM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
@Ghostbird |
Looks like we backported the fix to net7.0 branches here: #12914 This will be available in the next .NET 7.0 servicing release of .NET MAUI (Service Release 4) which should be available within the next few weeks. |
The easiest way in my opinion is using the .NET CLI. Personally I prefer
this as it works in almost all environments, also in CI environments such
as Github Actions. The .NET CLI is normally installed with the .NET SDK
which you probably have installed already.
See this [`dotnet workload install` manual](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-workload-install)
…On Wed, 22 Mar 2023, 17:26 FM1973, ***@***.***> wrote:
@Ghostbird <https://github.com/Ghostbird>
How do you install the latest version of maui without a visual studio
update?
As I´ve read, latest Visual Studio Versions contain a lot of bugs. But I´d
like to have the lates maui release.
—
Reply to this email directly, view it on GitHub
<#11275 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJFPZPEQQGPLILQ7KTIVCTW5MR5HANCNFSM6AAAAAAR5DB6KM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@Ghostbird |
Yes, but keep in mind
- You probably already have the latest .NET installed
- You probably already have the latest MAUI installed.
- This will probably not get you any newer version than the one installed
using the Visual Studio installer.
It's just a different, non-visual studio reliant way of installing these
tools. This is the more widely supported way to do the same thing.
Just try to run the `dotnet` commands in a shell and see if it's installed,
it probably is. Then you can use `dotnet workload list` to see if your MAUI
is up to date.
…On Wed, 22 Mar 2023, 19:30 FM1973, ***@***.***> wrote:
@Ghostbird <https://github.com/Ghostbird>
So you say to install the latest .net core SDK (7.0.4) and then use dotnet
workload update. Am I right?
—
Reply to this email directly, view it on GitHub
<#11275 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJFPZL2XOYHD4W2UCYBPCDW5NAMNANCNFSM6AAAAAAR5DB6KM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Congratulations on the new release pack and thanks! |
Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you! |
Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you! |
Your .NET SDK version is actually newer than mine (7.0.203), since you're running the preview. I think you're running a Visual Studio specific version of the dotnet workloads. I don't have experience with those. You could try to install the maui workloads using the In my case it lists this: $ dotnet workload list
Installed Workload Id Manifest Version Installation Source
--------------------------------------------------------------------
maui-android 7.0.81/7.0.100 SDK 7.0.200 If |
Yeah, our latest production release uses Android 13. I see that you're still on the .NET preview. Why are you trying this using a preview? I'd use the latest stable if I were you. If it works using the stable version, but not using the preview, please report a regression. Did you follow the instructions higher up in this thread? If so, your Android manifest should contain these two lines (although your <uses-sdk android:minSdkVersion="21"
android:targetSdkVersion="33" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="32"/> If you've tried all that and it still doesn't help, please post the actual error. |
This issue is about |
Description
My App was working and able to take pictures on Android 12 and .NET 6 but as soon as I upgraded to Android 13 and .NET 7, it stopped working. When I call this method:
FileResult photo = await MediaPicker.Default.CapturePhotoAsync();
I get this error: Microsoft.Maui.ApplicationModel.PermissionException: 'StorageWrite permission was not granted: Denied'.
I do have these declarations in the AndroidManifest.xml file:
Steps to Reproduce
Link to public reproduction project repository
https://github.com/FatCodeMonkey/MAUIPhoto
Version with bug
6.0.486 (current)
Last version that worked well
6.0.424
Affected platforms
Android
Affected platform versions
Android 13
Did you find any workaround?
No
Relevant log output
The text was updated successfully, but these errors were encountered: