Android @TargetApi(19)和字幕管理器
我正在开发一个应用程序,其中我使用API 19和功能闭路字幕,但并不是所有设备都安装了Kit kat,因此,当我使用此API时,我会说:Android @TargetApi(19)和字幕管理器,android,Android,我正在开发一个应用程序,其中我使用API 19和功能闭路字幕,但并不是所有设备都安装了Kit kat,因此,当我使用此API时,我会说: @TargetApi(19) private Boolean getStateAndroidCC() { CaptioningManager captioningManager = (CaptioningManager) context.getSystemService( Context.CAPTIONI
@TargetApi(19)
private Boolean getStateAndroidCC()
{
CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(
Context.CAPTIONING_SERVICE);
return captioningManager.isEnabled();
}
但是,当我运行应用程序并检查Logcat的控制台时,我看到这一行:
**找不到类“android.view.accessibility.CaptionManager”
你能帮我解决这个问题吗
因为我读到,如果我使用这个标记@TargetApi(19),这个问题将得到解决,但我无法修复它
提前谢谢
@TargetApi
注释用于抑制Lint API检查,因此不会出现编译错误
这意味着:我知道我正在调用一个API,该API可能在所有设备上都不可用,并且我正在正确处理它
因此,在调用有问题的API之前,必须检查是否正在运行Kitkat:
@TargetApi(19)
private Boolean getStateAndroidCC()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
CaptioningManager captioningManager = (CaptioningManager) context.getSystemService(
Context.CAPTIONING_SERVICE);
return captioningManager.isEnabled();
}
return false;
}
是的!!我对@TargetApi也有同样的想法。谢谢你的回复。我会这样做,然后我告诉你结果:)