I need to check dynamically if the used device supports openGL ES 2.0. How can i do that?
In addition to checking in code in the ways that others have mentioned, if you want to restrct it in market to ONLY those devices with 2.0 then in manifest:
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
You should do both, I've had people install the apk directly on to unsuitable devices and had to deal with strange exceptions. Now I throw a runTime:
private boolean detectOpenGLES20() {
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo info = am.getDeviceConfigurationInfo();
return (info.reqGlEsVersion >= 0x20000);
}
//in activity onCreate
if (!detectOpenGLES20()) {
throw new RuntimeException("Open GL ES 2.0 was not found on device");
}
Never used OpenGL ES, but saw it has the same glGetString
method as OpenGL. It should do the trick:
http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetString.xml
This code working Fine..
// Check if the system supports OpenGL ES 2.0.
final ActivityManager activityManager = ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
final ConfigurationInfo configurationInfo = activityManager
.getDeviceConfigurationInfo();
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
if (supportsEs2) {
Log.i("JO", "configurationInfo.reqGlEsVersion:"
+ configurationInfo.reqGlEsVersion + "supportsEs2:"
+ supportsEs2);
// Request an OpenGL ES 2.0 compatible context.
myGlsurfaceView.setEGLContextClientVersion(2);
final DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
// Set the renderer to our demo renderer, defined below.
myRenderer = new MyRenderer(this, myGlsurfaceView);
} else {
// This is where you could create an OpenGL ES 1.x compatible
// renderer if you wanted to support both ES 1 and ES 2.
return;
}
You can use this code in your code:
int result;
ActivityManager activityManager =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo configInfo = activityManager.getDeviceConfigurationInfo();
if (configInfo.reqGlEsVersion != ConfigurationInfo.GL_ES_VERSION_UNDEFINED) {
result= configInfo.reqGlEsVersion;
} else {
result= 1 << 16; // Lack of property means OpenGL ES version 1
}
Log.e("reqGlEsVersion", String.valueOf(result));
Log.e("getGlEsVersion", configInfo.getGlEsVersion());
Yes. The following code will do the trick:
final ActivityManager activityManager =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final ConfigurationInfo configurationInfo =
activityManager.getDeviceConfigurationInfo();
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
Read this for more info: http://www.learnopengles.com/android-lesson-one-getting-started/
You may also require want to restrict devices that don't support 2.0 from seeing your app in the marketplace by adding the following to your manifest:
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
See also the doc of uses-feature.
For a while, I've been looking for the same answer, too. But unfortunately, I couldn't find a proper description for that. I just found a way a minute ago by myself, and I feel like I'd like to share it with everyone.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FeatureInfo[] list = this.getPackageManager()
.getSystemAvailableFeatures();
Toast.makeText(this,
"OpenGL ES Version: " + list[list.length - 1].getGlEsVersion(),
Toast.LENGTH_LONG).show();
}