Not easy to add a "AndroidResource" to a maui project and `Resource` is ambiguous
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
To play a sound when earn an achievement, you need to write platform specific Android code and give the SoundPool object an Android Resource Id. To schedule a local notification/alarm, you need to give an Android Resource Id for the badge image and custom sound file.
I am unable to find any documentation on managing Assets so that they generate an Android Resource Id in the Resource.designer.cs file. When adding a .wav file into the Maui raw asset folder the default build action will not generate the resource id. When adding a .wav file into the Platforms/Android/Resources/Raw folder the default build action doesn't generate the resource id.
Also, Visual Studio 2022 does not give good hints for the Resource namespace.
'Resource' is an ambiguous reference between 'Microsoft.Maui.Controls.Resource' and 'Microsoft.Maui.Graphics.Resource'
This list should include [App Root Namespace].Resource. Again, there is no documentation anywhere on how to access the Android Resources for platform specific code.
The main issue is that `AndroidAsset` is for the "assets" but we need a way to add RAW resources.
### Steps to Reproduce
1. Create new Maui Project
2. Add a test.wav file to the Maui Resources/Raw folder (do not set a build action)
3. In a platform specific file in Android platform code
4. "int test = Resource.Raw.test;"
5. Try to figure out how to make this line work.
### Link to public reproduction project repository
:)
### Version with bug
6.0.486 (current)
### Last version that worked well
Unknown/Other
### Affected platforms
Android
### Affected platform versions
All
### Did you find any workaround?
The current workaround is to manually add the file to `Platforms\Android\Resources\raw` and then use `AppNamespace.Resources.raw` but this is not intuitive nor documented.
### Relevant log output
_No response_
Contributor guide
Research direction
Start with the documented paths in Resources/Raw and Platforms/Android/Resources/raw, then inspect how Resource.designer.cs exposes Android resource IDs and how the Resource namespace is resolved in platform-specific code. Done means the documentation explains the required build action, raw-resource placement, generated namespace, and how to avoid the ambiguous Resource reference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- documentation, mobile-dev
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100