I am following some tutorials in android about how to create an app that can toggle the silent mode. Everything is fine until I got this errors:

The method getDrawable(int) from the type Resources is deprecated
Can you help me with this? I am new in Android. By the way I am using API 23 for this.
getResources().getDrawable() is now deprecated.
You should use the following code from the support library instead:
ContextCompat.getDrawable(context, R.drawable.***)
Using this method is equivalent to calling:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return resources.getDrawable(id, context.getTheme());
} else {
return resources.getDrawable(id);
}
As of API 21, you should use the getDrawable(int, Theme) method instead of getDrawable(int), as it allows you to fetch a drawable object associated with a particular resource ID for the given screen density/theme. Calling the deprecated getDrawable(int) method is equivalent to calling getDrawable(int, null).
for more detail visit Here.
Android getResources().getDrawable() deprecated API 22
This is just a warning telling you that there is no support for this method by google and you shouldn't use it. You can use getDrawable(R.drawable.phone_silent,null); This null is for theme. If you have specific theme then you can provide theme here else null will suffice. Please accept if it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With