-1

I know this question is asked several times. My problem is to use a mute function which is depricated now. But the new solutions cannot be applied to lower versions. I have used this function within a if else loop as shown in the code given below. But while inspecting the code, it is showing a Code maturity issue. Is there any way to avoid this inspection issue. Can I use any annotations or something like that?

 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            audioManager.adjustVolume(AudioManager.ADJUST_MUTE, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
        } else {
            audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
        }

Hope to get a good solution. Thanks in advance

  • Can you post the full text of the issue? – Luca Nicoletti Dec 21 '16 at 09:50
  • Simply suppress the warning by adding `@SuppressWarnings("..."` before your function signature. – Phantômaxx Dec 21 '16 at 09:53
  • I can't supress this warning. Rather i want to avoid this. – MOHAMMED NIHAL Dec 21 '16 at 09:55
  • Possible duplicate of [How can I suppress javac warnings about deprecated api?](http://stackoverflow.com/questions/1554538/how-can-i-suppress-javac-warnings-about-deprecated-api) – Ihor Dobrovolskyi Dec 21 '16 at 10:06
  • If this method is deprecated that's the state. You either use the new method that is linked in the javaDoc ( in most cases ) or suppress the warning with the annotation. It is generally not recommended to use deprecated code, specially when if comes from a sdk, because they provide a new one in most cases that is better in some ways. Also you risk using a function that will be completely removed at some point, resulting in a broken software. – Nico Dec 21 '16 at 10:25

2 Answers2

1

You can use SuppressWarnings annotation to ignore warnings. To ignore "deprecated" warning, you have to add @SuppressWarnings("deprecated") to your method.

Ihor Dobrovolskyi
  • 1,241
  • 9
  • 19
1

You can use deprecated method by using @SuppressWarnings anotation in java ,for Detail refer Check Here

Community
  • 1
  • 1
Rahul Chaube
  • 334
  • 3
  • 11