A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hello @Big_Bear_7 ,
Thanks for your question.
PreferenceManager.GetDefaultSharedPreferences() was deprecated starting from Android 10 (API 29). Your app's minimum supported OS version is API 31, which means every single device that runs your app is on a version where this API is already deprecated. While it won't crash today, deprecated APIs can be removed in future Android versions, and Google Play may flag this as a concern going forward.
Since you already have a SharedCode project shared between Android and iOS, I recommend replacing all platform-specific code with the built-in .NET MAUI Preferences API. This works on Android, iOS, Windows, and macOS - no if ANDROID / if IOS blocks needed.
Replace your SharedCode if block:
deviceToken = Microsoft.Maui.Storage.Preferences.Default.Get("my_token", string.Empty);
Replace storeToken() in MyFirebaseMessagingService.cs:
private void storeToken(string token)
{
Microsoft.Maui.Storage.Preferences.Default.Set("my_token", token);
}
Should you add targetSdkVersion to your .csproj?
Yes, you should. Your .csproj currently only sets:
<SupportedOSPlatformVersion>31.0</SupportedOSPlatformVersion>
This only tells the build system the minimum Android version your app runs on. Since you are targeting API 36, you should also declare this explicitly. In modern .NET MAUI SDK-style projects, the correct property to use is TargetPlatformVersion:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0-android</TargetFramework>
<SupportedOSPlatformVersion>31.0</SupportedOSPlatformVersion>
<TargetPlatformVersion>36.0</TargetPlatformVersion>
<OutputType>Exe</OutputType>
...
</PropertyGroup>
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.