使用 Android APK 2.2 打开硬件加速(如果可用)(例如 Android 3+)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10339277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Turn on hardware acceleration if available (such Android 3+) with Android APK 2.2
提问by Marcos Vasconcelos
I developed a application for Android 3.0, and it's runs perfectly well, but the client insist on compatibility with 2.2 devices.
我为Android 3.0 开发了一个应用程序,它运行得很好,但客户端坚持与2.2 设备兼容。
Disabling hardware acceleration, using Android Compatibility Package, a NIO-backport support (For tasks and executors) and some reimplementation of View methods I was able to port my app for Android 2.2 and works really good, but if I run this apk into a newer device the performance is extremely slowly, so I want to know how to turn on hardware acceleration if available but still uses my 2.2 APK.
禁用硬件加速、使用 Android 兼容包、NIO 反向端口支持(用于任务和执行程序)和一些视图方法的重新实现我能够将我的应用程序移植到 Android 2.2 并且工作得非常好,但是如果我将此 apk 运行到更新的设备的性能非常慢,所以我想知道如何打开硬件加速(如果可用)但仍然使用我的 2.2 APK。
回答by CommonsWare
Add android:hardwareAccelerated="true"
to your manifest, either for the <activity>
or the <application>
.
添加android:hardwareAccelerated="true"
到您的清单,无论是<activity>
还是<application>
.
This attribute will be ignored on older versions of Android, but will be honored on Android 3.0+.
此属性在旧版本的 Android 上将被忽略,但在 Android 3.0+ 上会得到尊重。
This will require you to have set your build target to API Level 11 or higher, but you probably already have that.
这将要求您将构建目标设置为 API 级别 11 或更高,但您可能已经拥有了。
回答by Tapa Save
If you need support devises with old OS (2.3.X and older) version, not add android:hardwareAccelerated="true"
to your manifest, try add this code in your java:
如果您需要旧操作系统(2.3.X 及更旧)版本的支持设备,而不是添加android:hardwareAccelerated="true"
到您的清单中,请尝试在您的 java 中添加以下代码:
try { if( Build.VERSION.SDK_INT >= 11) getWindow().setFlags( 16777216, 16777216); } catch( Exception e) {} // FLAG_HARDWARE_ACCELERATED == 16777216 (0x01000000)
This is work in OS 3.0++ and not call error on 2.3.X and older.
这在 OS 3.0++ 中有效,在 2.3.X 及更早版本上不会调用错误。