Android:在运行时获取TargetSDKVersion [英] Android: Get TargetSDKVersion in runtime
问题描述
我可以在运行时获取使用过的TargetSDKVersion吗?
Can I get the used TargetSDKVersion in runtime?
这是由于以下事实:Android API 19>中的WebView处理像素的方式与pre 19不同.
This is due to the fact that the WebView in Android API 19> handles pixels differently than pre 19.
这是一个库,所以我不想让开发人员手动输入它.
This is for a library and so I would not like to have the developer enter it manually.
我的评论:我正在使用Nexus 5 API 21棒棒糖.更改TargetSDKVersion会将html的javascript读取宽度的方式更改为屏幕密度的倍数.我刚刚将其更改为14,然后更改为19,我确认了这一点.
My comment: I am using my Nexus 5 API 21 Lollipop. Changing TargetSDKVersion changes the way javascript of the html reads the widths by a multiple of the screen density. I have just changed it to 14 then to 19, and I confirm this.
推荐答案
此处)
int version = 0;
IPackageManager pm = AppGlobals.getPackageManager();
try {
ApplicationInfo applicationInfo = pm.getApplicationInfo(yourAppName, 0);
if (applicationInfo != null) {
version = applicationInfo.targetSdkVersion;
}
}
OR
如果我们谈论设备操作系统版本
If we talk about device OS version
android.os.Build.VERSION.SDK_INT
这篇关于Android:在运行时获取TargetSDKVersion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!