-
Notifications
You must be signed in to change notification settings - Fork 564
Description
Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
VS 2022 17.4.1, .NET 7
Description
I am using this property to get the installed app version:
public static string VersionString => (OperatingSystem.IsAndroidVersionAtLeast(33) ?
Application.Context.PackageManager.GetPackageInfo(PackageName, PackageManager.PackageInfoFlags.Of(0)) :
Application.Context.PackageManager.GetPackageInfo(PackageName, 0)).VersionName;
The old (now deprecated) GetPackageInfo method still emits this warning, even though OperatingSystem.IsAndroidVersionAtLeast is used:
Warning CS0618 'PackageManager.GetPackageInfo(string, PackageInfoFlags)' is obsolete: 'deprecated'
This is because of this attribute:
[System.Obsolete("deprecated")]
I think this attribute should be used instead:
[ObsoletedOSPlatform("android30.0")]
I know this is rather nitpicking, but there might be other usages of the old Obsolete attribute that could be replaced with the ObsoletedOSPlatform attribute. In the PackageManager class alone there are also these methods currently annotated with the old attribute:
https://developer.android.com/reference/android/content/pm/PackageManager#addPreferredActivity(android.content.IntentFilter,%20int,%20android.content.ComponentName[],%20android.content.ComponentName)
https://developer.android.com/reference/android/content/pm/PackageManager#getPackageGids(java.lang.String,%20int)
https://developer.android.com/reference/android/content/pm/PackageManager#removePackageFromPreferred(java.lang.String)
https://developer.android.com/reference/android/content/pm/PackageManager#addPackageToPreferred(java.lang.String)
Steps to Reproduce
- Create new .NET 6 project
- Add property as shown above
- Build app / check warnings window
Did you find any workaround?
No response
Relevant log output
No response