Share via

This call site is reachable on: 'Android' 31.0 and later. 'PreferenceManager.GetDefaultSharedPreferences(Context?)' is obsoleted on: 'Android' 29.0 and later (This class is obsoleted in this android platform).

Big_Bear_7 20 Reputation points
2026-06-15T21:43:30.5733333+00:00

I get this warning in a class in my SharedCode project. Is it necessary to change something or can I ignore the warning?

This call site is reachable on: 'Android' 31.0 and later. 'PreferenceManager.GetDefaultSharedPreferences(Context?)' is obsoleted on: 'Android' 29.0 and later (This class is obsoleted in this android platform).

#if IOS
            deviceToken = NSUserDefaults.StandardUserDefaults.StringForKey("PushDeviceToken");  
#elif ANDROID
                    ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(Android.App.Application.Context);
                    deviceToken = prefs.GetString("my_token", "");           
#endif

In addition, I use the following code in MyFirebaseMessagingService.cs in my Android project to save the token:

      public override void OnNewToken(string token)
      {
          Log.Debug(TAG, "Refreshed token: " + token);
          storeToken(token); 
      }        

      private void storeToken(String token)
      {
          //saving the token on shared preferences
          ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
          ISharedPreferencesEditor editor = prefs.Edit();
          editor.PutString("my_token", token);
          editor.Apply();          
      }

Target OS version of my Android project is 36.0. In addition, I use this Android .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0-android</TargetFramework>
    <SupportedOSPlatformVersion>31.0</SupportedOSPlatformVersion>
    <OutputType>Exe</OutputType> 
    ...

The Target OS version is not in my Android .csproj file. Should I add something in my Android .csproj file because I use Target OS version 36.0?

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author

Nancy Vo (WICLOUD CORPORATION) 6,510 Reputation points Microsoft External Staff Moderator
2026-06-16T04:21:03.5033333+00:00

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.

Was this answer helpful?

2 people found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.