How can I detect witch openGl version my device is running? All what I found is android saying that all devices 2.3+ support openGL 2.0. Witch is not true as I found devices that been upgraded to version 2.3 but they system doesn't support it.
glGetString(GL_VERSION)
See more at: http://www.khronos.org/opengles/documentation/opengles1_0/html/glGetString.html
From the Android CTS's (Compatibility Test Suite) OpenGlEsVersionTest.java:
private static int getVersionFromPackageManager(Context context) {
PackageManager packageManager = context.getPackageManager();
FeatureInfo[] featureInfos = packageManager.getSystemAvailableFeatures();
if (featureInfos != null && featureInfos.length > 0) {
for (FeatureInfo featureInfo : featureInfos) {
// Null feature name means this feature is the open gl es version feature.
if (featureInfo.name == null) {
if (featureInfo.reqGlEsVersion != FeatureInfo.GL_ES_VERSION_UNDEFINED) {
return getMajorVersion(featureInfo.reqGlEsVersion);
} else {
return 1; // Lack of property means OpenGL ES version 1
}
}
}
}
return 1;
}
/** #see FeatureInfo#getGlEsVersion() */
private static int getMajorVersion(int glEsVersion) {
return ((glEsVersion & 0xffff0000) >> 16);
}
It actually provides a few other ways as well and the test verifies that they all return the same results.
Related
As you know, Xiaomi devices have their own system of permissions. I'm testing my application on the device xiaomi redmi 3, api 22, android 5.1.1. I want to check if there is permission to access the camera and audio. But the standard way does not work:
ContextCompat.checkSelfPermission(getActivity().getApplicationContext(), "android.permission.CAMERA");
returns 0, although this is not true.
I found another way, but it also does not work correctly:
boolean b = hasSelfPermissionForXiaomi(getActivity(),"android.permission.CAMERA");
private boolean hasSelfPermissionForXiaomi(Context context,String permission){
String permissionTop = AppOpsManagerCompat.permissionToOp(permission);
if(permissionTop == null){
// not dangerous
return true;
}
int noteOp = AppOpsManagerCompat.noteOp(context,permissionTop, Process.myUid(),context.getPackageName());
return noteOp == AppOpsManagerCompat.MODE_ALLOWED && checkSelfPermission(context,permission) == PackageManager.PERMISSION_GRANTED;
}
b = true, although this is not true.
Guys, did any of you understand how to check permissions on xiaomi devices ???
I am trying to create a 1v3 or 4v4 conferencing(whatever you call it) android app, i have successfully connected 4 people together using webrtc and socket.io.
But when i disconnect one of the users i get webrtc native crash
Fatal signal 11 (SIGSEGV), code 1, fault addr 0xb8 in tid 17650 (Thread-648)
Same code works in moto c but crashes on other devices.
webrtc version used - compile 'io.pristine:libjingle:9694#aar'
onDisconnect(){
if (null != peerConnection2) {
peerConnection2.removeStream(localMediaStream);
peerConnection2.close();
peerConnection2 = null;
}
if (null != peerConnection3) {
peerConnection3.dispose();
peerConnection3 = null;
}
if (null != localVideoSource) {
localVideoSource.dispose();
localVideoSource = null;
}
if (null != peerConnectionFactory) {
audioManager.setMode(AudioManager.MODE_NORMAL);
audioManager.setSpeakerphoneOn(false);
peerConnectionFactory.dispose(); <<<<--- THIS IS WHERE THE APP CRASHES.
peerConnectionFactory = null;
}
}
I am not sure if updating the version will help me with this bug, even if i go for updating it to new version, i am unable to find any proper documentation or blog related to it, it'll be great if you can point me to any known link(blog/documentaion) for latest version of libjingle.
I am trying to get all the available system features on my Nexus9 device using PackageManager.getSystemAvailableFeatures().
From Android 5.0 Lollipop, Google introduced new camera APIs (camera2). I think Nexus9 is using Camera2 APIs.
When I am running this API on Nexus9 device it is not listing camera2 APIs features like:
android.hardware.camera.level.full
android.hardware.camera.capability.manual_post_processing
android.hardware.camera.capability.manual_sensor
android.hardware.camera.capability.raw
I am using below code to get all the available features:
public final static boolean isFeatureAvailable(Context context, String feature) {
final PackageManager packageManager = context.getPackageManager();
final FeatureInfo[] featuresList = packageManager.getSystemAvailableFeatures();
for (FeatureInfo f : featuresList) {
if (f.name != null && f.name.equals(feature)) {
return true;
}
}
return false;
}
Questions:
Is Nexus9 using & having camera2 API features?
If answer is yes for above question, then Why it is not listing these system level features? I am doing something wrong?
Thanks for your comments in advance!
Is Nexus9 using & having camera2 API features?
Yes. All Android Lollipop devices and newer have the camera2 APIs.
If answer is yes for above question, then Why it is not listing these system level features?
Supported APIs are usually not included in the system features list. Most system features are related to things that can vary from device to device and are usually related to hardware features (e.g. sensors, bluetooth, NFC, etc) or system-wide software support (e.g. backup, device management, multi-user, etc). There's a list of all supported capabilities here.
I am doing something wrong?
According to the docs, the recommended way to check if the camera2 APIs exist is by requesting the camera service via:
CameraManager cameraManager = (CameraManager) getSystemService("camera");
Basically this method returns null if the camera2 APIs aren't available, either because the version of Android is too old (sdkVersion < 21) or because they've been removed from the system (e.g. via a custom ROM).
Finally I was able to get answers to my questions.
Is Nexus9 using & having camera2 API features?
Ans: Yes Nexus9 is having and using Camera2 APIs. It has LIMITED supported hardware level and has capabilities: BACKWARD_COMPATIBLE and MANUAL_SENSOR
If answer is yes for above question, then Why it is not listing these system level features? I am doing something wrong?
Ans: Because using above code I am listing features not capabilities. To list down the capabilities I used below code:
Activity activity = getActivity();
CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
try {
for (String cameraId : manager.getCameraIdList()) {
CameraCharacteristics characteristics
= manager.getCameraCharacteristics(cameraId);
if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL) {
Log.d("Camera2 SUPPORTED_HARDWARE_LEVEL: ", "FULL");
} else if (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
Log.d("Camera2 SUPPORTED_HARDWARE_LEVEL: ", "LEGACY");
} else if(characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED) {
Log.d("Camera2 SUPPORTED_HARDWARE_LEVEL: ", "LIMITED");
}
StringBuilder stringBuilder = new StringBuilder();
for (int i=0; i<characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES).length; i++) {
if(characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)[i] ==CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE) {
stringBuilder.append("BACKWARD_COMPATIBLE" + " ");
} else if (characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)[i] ==CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING) {
stringBuilder.append("MANUAL_POST_PROCESSING" + " ");
} else if(characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)[i] ==CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR) {
stringBuilder.append("MANUAL_SENSOR" + " ");
} else if (characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES)[i] ==CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES_RAW) {
stringBuilder.append("RAW" + " ");
}
}
Log.d("Camera2: ", stringBuilder.toString());
As we all know from Android 5.0.64bit support is there. I have very simple question. Can we check programmatically in what mode any application is running i.e. 32bit or 64bit? For example: I have Facebook app running on my Nexus 9, so can I check using my android app if Facebook app's process is running in 32bit mode or 64bit mode?
In Nexus 5x
String arch = System.getProperty("os.arch");
returns
armv8l
it is not aarch64 and my code broke. However,
root#bullhead:/ # uname -m
aarch64
root#bullhead:/ # getprop ro.product.cpu.abilist
arm64-v8a,armeabi-v7a,armeabi
Wired. So I changed my code to
boolean is64 = (android.os.Build.VERSION.SDK_INT >= 21) && System.getProperty("ro.product.cpu.abilist").contains("64");
Updated on 2016-02-11
In Samsung Samsung Galaxy S5 Neo, Android 5.1.1
String arch = System.getProperty("os.arch");
returns aarch64 but it is not 64-bit device!!!
ro.product.cpu.abilist returns armeabi-v7a,armeabi
bool is64Bit = System.getProperty("ro.product.cpu.abilist").contains("64");
check is the only way to check.
Try System.getProperty("os.arch").
I haven't tried it on 64-bit android, but it must return something like 'aarch64' in case of 64 bit device.
http://developer.android.com/reference/java/lang/System.html#getProperty(java.lang.String)
public static boolean is64Bit() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//Added in API level 23
return Process.is64Bit();
}
try {
Class cls = Class.forName("dalvik.system.VMRuntime");
Method getRuntimeMethod = cls.getDeclaredMethod("getRuntime");
Object vmRuntime = getRuntimeMethod.invoke(null);
Method is64BitMethod = cls.getDeclaredMethod("is64Bit");
Object is64Bit = is64BitMethod.invoke(vmRuntime);
if (is64Bit instanceof Boolean) {
return (boolean) is64Bit;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
IMO, you can use reflect to get the result of is64Bit. Android 6.0 began to provide this api to check your process.
android.os.Process.is64Bit()
In my experience (if your minSdkVersion is >= 21) the best way is to check the size of the array Build.SUPPORTED_64_BIT_ABIS.
(see https://developer.android.com/reference/android/os/Build#SUPPORTED_64_BIT_ABIS)
Something like this:
public static boolean is64Bit() {
return (Build.SUPPORTED_64_BIT_ABIS!= null && Build.SUPPORTED_64_BIT_ABIS.length >0);
}
What makes you think your device isn't 64-bit? The specs for the phone indicate it uses an Exynos 7 Octa 7580 which is arm8 and 64-bit.
boolean is64Arch = Build.CPU_ABI.equalsIgnoreCase("x86_64") || Build.CPU_ABI.equalsIgnoreCase("arm64-v8a");
Is there any way to get the API version that the phone is currently running?
As described in the Android documentation, the SDK level (integer) the phone is running is available in:
android.os.Build.VERSION.SDK_INT
The class corresponding to this int is in the android.os.Build.VERSION_CODES class.
Code example:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP){
// Do something for lollipop and above versions
} else{
// do something for phones running an SDK before lollipop
}
Edit: This SDK_INT is available since Donut (android 1.6 / API4) so make sure your application is not retro-compatible with Cupcake (android 1.5 / API3) when you use it or your application will crash (thanks to Programmer Bruce for the precision).
Corresponding android documentation is here and here
Very easy:
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;
int version = Build.VERSION.SDK_INT;
String versionRelease = Build.VERSION.RELEASE;
Log.e("MyActivity", "manufacturer " + manufacturer
+ " \n model " + model
+ " \n version " + version
+ " \n versionRelease " + versionRelease
);
Output:
E/MyActivity: manufacturer ManufacturerX
model SM-T310
version 19
versionRelease 4.4.2
Build.VERSION.RELEASE;
That will give you the actual numbers of your version; aka 2.3.3 or 2.2.
The problem with using Build.VERSION.SDK_INT is if you have a rooted phone or custom rom, you could have a non standard OS (aka my android is running 2.3.5) and that will return a null when using Build.VERSION.SDK_INT so Build.VERSION.RELEASE will work no matter using standard Android version or not !
To use it, you could just do this;
String androidOS = Build.VERSION.RELEASE;
try this:
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
// only for gingerbread and newer versions
}
Taking into account all said, here is the code I use for detecting if device has Froyo or newer Android OS (2.2+):
public static boolean froyoOrNewer() {
// SDK_INT is introduced in 1.6 (API Level 4) so code referencing that would fail
// Also we can't use SDK_INT since some modified ROMs play around with this value, RELEASE is most versatile variable
if (android.os.Build.VERSION.RELEASE.startsWith("1.") ||
android.os.Build.VERSION.RELEASE.startsWith("2.0") ||
android.os.Build.VERSION.RELEASE.startsWith("2.1"))
return false;
return true;
}
Obviously, you can modify that if condition to take into account 1.0 & 1.5 versions of Android in case you need generic checker. You will probably end up with something like this:
// returns true if current Android OS on device is >= verCode
public static boolean androidMinimum(int verCode) {
if (android.os.Build.VERSION.RELEASE.startsWith("1.0"))
return verCode == 1;
else if (android.os.Build.VERSION.RELEASE.startsWith("1.1")) {
return verCode <= 2;
} else if (android.os.Build.VERSION.RELEASE.startsWith("1.5")) {
return verCode <= 3;
} else {
return android.os.Build.VERSION.SDK_INT >= verCode;
}
}
Let me know if code is not working for you.
android.os.Build.VERSION.SDK should give you the value of the API Level. You can easily find the mapping from api level to android version in the android documentation. I believe, 8 is for 2.2, 7 for 2.1, and so on.
SDK.INT is supported for Android 1.6 and up
SDK is supported for all versions
So I do:
String sdk_version_number = android.os.Build.VERSION.SDK;
Credits to: CommonsWare over this answer
Got it. Its using the getApplicationInfo() method of the Context class.
I generally prefer to add these codes in a function to get the Android version:
int whichAndroidVersion;
whichAndroidVersion= Build.VERSION.SDK_INT;
textView.setText("" + whichAndroidVersion); //If you don't use "" then app crashes.
For example, that code above will set the text into my textView as "29" now.
i prefer have the version as number to be handeled more easyway than i wrote this:
public static float getAPIVerison() {
Float f = null;
try {
StringBuilder strBuild = new StringBuilder();
strBuild.append(android.os.Build.VERSION.RELEASE.substring(0, 2));
f = new Float(strBuild.toString());
} catch (NumberFormatException e) {
Log.e("", "error retriving api version" + e.getMessage());
}
return f.floatValue();
}
I improved code i used
public static float getAPIVerison() {
float f=1f;
try {
StringBuilder strBuild = new StringBuilder();
strBuild.append(android.os.Build.VERSION.RELEASE.substring(0, 2));
f= Float.valueOf(strBuild.toString());
} catch (NumberFormatException e) {
Log.e("myApp", "error retriving api version" + e.getMessage());
}
return f;
}
Like this:
String versionRelease = BuildConfig.VERSION_NAME;
versionRelease :- 2.1.17
Please make sure your import package is correct ( import package your_application_package_name, otherwise it will not work properly).