运行时检测硬件加速:Android
是否有可能在创建活动时一致检测其是否启用了硬件加速?我担心我的库的用户会在他们不应该的时候通过清单启用它,因为他们没有专门为我的活动禁用它(正如我指示他们那样) 我能找到的唯一可靠的信息()是我可以查询运行时检测硬件加速:Android,android,android-activity,hardware-acceleration,Android,Android Activity,Hardware Acceleration,是否有可能在创建活动时一致检测其是否启用了硬件加速?我担心我的库的用户会在他们不应该的时候通过清单启用它,因为他们没有专门为我的活动禁用它(正如我指示他们那样) 我能找到的唯一可靠的信息()是我可以查询View.isHardwareAccelerated()和Canvas.isHardwareAccelerated()。但是,出于我的目的,我希望在显示我的库的活动时确保它处于关闭状态。到目前为止,我无法得到任何东西来报告在打开或关闭时一致的是/否。我尝试在虚拟视图中进行黑客攻击,将其设置为我的活
View.isHardwareAccelerated()
和Canvas.isHardwareAccelerated()
。但是,出于我的目的,我希望在显示我的库的活动时确保它处于关闭状态。到目前为止,我无法得到任何东西来报告在打开或关闭时一致的是/否。我尝试在虚拟视图中进行黑客攻击,将其设置为我的活动,然后对其进行测试,但它总是返回false。此外,我还尝试测试了Window.getAttributes().flags
,但它们也没有显示它
我之所以测试此功能,是因为我的库的硬件加速绘制路径无法正常运行,而且似乎没有任何方法可以修复它。
请尝试在flags
中为活动标记硬件加速,你可以通过getActivityInfo()
从PackageManager
获得它,我是Android新手,所以即使有上面答案中给出的线索,我也会被卡住。。四处搜索,在谷歌的海洋中找到了这段代码。希望它能帮助别人
/**
* Returns true if the given Activity has hardware acceleration enabled
* in its manifest, or in its foreground window.
*
* TODO(husky): Remove when initialize() is refactored (see TODO there)
* TODO(dtrainor) This is still used by other classes. Make sure to pull some version of this
* out before removing it.
*/
public static boolean hasHardwareAcceleration(Activity activity) {
// Has HW acceleration been enabled manually in the current window?
Window window = activity.getWindow();
if (window != null) {
if ((window.getAttributes().flags
& WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0) {
return true;
}
}
// Has HW acceleration been enabled in the manifest?
try {
ActivityInfo info = activity.getPackageManager().getActivityInfo(
activity.getComponentName(), 0);
if ((info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0) {
return true;
}
} catch (PackageManager.NameNotFoundException e) {
Log.e("Chrome", "getActivityInfo(self) should not fail");
}
return false;
}
另一种方法是从活动的onCreate()方法调用getDecorView().isHardwareAccelerated()。。请同时回答以下问题。。