Created
February 27, 2025 11:16
-
-
Save dipendra-sharma/3f2da7283d83ba7183f3a0e239444b2f to your computer and use it in GitHub Desktop.
Retrieving OpenGLES version and Vulkan version in Android using kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dipendrasharma.myapplication | |
import android.app.ActivityManager | |
import android.content.Context | |
import android.content.pm.ConfigurationInfo | |
fun getOpenGLESVersion(context: Context): String { | |
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager | |
val configurationInfo: ConfigurationInfo = activityManager.deviceConfigurationInfo | |
val version = configurationInfo.reqGlEsVersion | |
val majorVersion = (version and 0xFFFF0000.toInt()) shr 16 | |
val minorVersion = version and 0x0000FFFF | |
return "$majorVersion.$minorVersion" | |
} | |
fun getVulkanVersion(context: Context): String { | |
val featureName = "android.hardware.vulkan.version" | |
val featureInfo = context.packageManager.systemAvailableFeatures | |
.find { it.name == featureName } | |
return if (featureInfo != null) { | |
val version = featureInfo.version | |
val majorVersion = (version ushr 22) and 0x3FF | |
val minorVersion = (version ushr 12) and 0x3FF | |
val patchVersion = version and 0xFFF | |
"$majorVersion.$minorVersion.$patchVersion" | |
} else { | |
"Vulkan not supported" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment