Is there a way to check if Android device supports

2019-01-13 18:20发布

问题:

I need to check dynamically if the used device supports openGL ES 2.0. How can i do that?

回答1:

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.



回答2:

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");
    }


回答3:

Determining OpenGL extensions :

Implementations of OpenGL vary by Android device in terms of the extensions to the OpenGL ES API that are supported. These extensions include texture compressions, but typically also include other extensions to the OpenGL feature set.

To determine what texture compression formats, and other OpenGL extensions, are supported on a particular device:

Run the following code on your target devices to determine what texture compression formats are supported:

  String extensions = javax.microedition.khronos.opengles.GL10.glGetString(GL10.GL_EXTENSIONS);

Warning: The results of this call vary by device! You must run this call on several target devices to determine what compression types are commonly supported. Review the output of this method to determine what OpenGL extensions are supported on the device.



回答4:

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());


回答5:

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



回答6:

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;
    }


回答7:

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();
}