Created
April 12, 2013 09:43
-
-
Save ptekchand/5370884 to your computer and use it in GitHub Desktop.
Checking if code is running on an Android emulator seems to be an inexact process. This helper traces all the (static String) variables inside the android.os.Build class. This may help you choose a workaround/hack of your choice when required.
http://stackoverflow.com/questions/2799097/how-can-i-detect-when-an-android-application-is-running-in-t…
This file contains 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
import java.lang.reflect.Field; | |
import java.lang.reflect.Modifier; | |
import android.os.Build; | |
private void traceBuildValues() { | |
Build build = new Build(); | |
Class<?> c = build.getClass(); | |
Field[] fieldArray = c.getDeclaredFields(); | |
for(Field aField : fieldArray) { | |
int modifiers = aField.getModifiers(); | |
if(Modifier.isStatic(modifiers)) { | |
String fieldName = aField.getName(); | |
//String fullFieldDeclStr = aField.toGenericString(); | |
Object fieldType = aField.getType(); | |
if(String.class.equals(fieldType)) { | |
String fieldValue = ""; | |
try { | |
fieldValue = (String)aField.get(build); | |
} catch (IllegalArgumentException e) { | |
e.printStackTrace(); | |
continue; | |
} catch (IllegalAccessException e) { | |
e.printStackTrace(); | |
continue; | |
} | |
Log.d("TraceBuild", "Build."+fieldName+" = "+fieldValue); | |
} | |
} | |
} | |
} | |
/* | |
Sample output on an x86 emulator image running Android 4.1.1 | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.BOARD = unknown | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.BOOTLOADER = unknown | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.BRAND = generic_x86 | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.CPU_ABI = x86 | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.CPU_ABI2 = unknown | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.DEVICE = generic_x86 | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.DISPLAY = sdk_x86-eng 4.1.1 JRO03H eng.android-build.20120823.114606 test-keys | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.FINGERPRINT = unknown | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.HARDWARE = goldfish | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.HOST = intelotc-srv | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.ID = JRO03H | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.MANUFACTURER = unknown | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.MODEL = Android SDK built for x86 | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.PRODUCT = sdk_x86 | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.RADIO = unknown | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.SERIAL = unknown | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.TAGS = test-keys | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.TYPE = eng | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.UNKNOWN = unknown | |
04-12 13:56:54.928: D/TraceBuild(2551): Build.USER = android-build | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment