Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Version Check Issue (deprecated)

Recently I updated an app to use Notification Channel to display notifications on Oreo as Oreo requires Notification Channel, that works fine but Notification Channels are not supported by older android versions hence I am trying to perform a check to see if you is running on Oreo then use create notification channel function. The problem is when I use the following to check

Build.VERSION_CODES.O

it says it is deprecated? Every old post on internet is referring to Build.VERSION_CODES.O but it is deprecated.

Is there a a way to check this? What should I do?

like image 322
Ali Avatar asked Mar 07 '23 08:03

Ali


1 Answers

Not deprecated, but obsolete:

[Register ("O", ApiSince = 26)]
[Obsolete ("This constant will be removed in the future version. Use Android.OS.BuildVersionCodes enum directly instead of this field.")]
public const BuildVersionCodes O = BuildVersionCodes.O;

Instead of using Build.VERSION_CODES.? use Android.OS.BuildVersionCodes.? instead:

i.e.

if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{
  ~~~
}
like image 196
SushiHangover Avatar answered Mar 10 '23 10:03

SushiHangover