Created
April 3, 2012 10:59
-
-
Save deltheil/2291028 to your computer and use it in GitHub Desktop.
Android Native API (JNI): get the device name
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
#include <stdio.h> | |
#include <string.h> | |
#include <sys/system_properties.h> | |
/* Get device name | |
-- | |
1/ Compile with the Android NDK Toolchain: | |
arm-linux-androideabi-gcc -static pname.c -o pname | |
2/ Transfer on device: | |
adb push pname /data/local/tmp | |
3/ Run: | |
adb shell | |
$ /data/local/tmp/pname | |
[device]: [HTC/HTC Sensation Z710e] | |
NOTE: these properties can be queried via adb: | |
adb shell getprop ro.product.manufacturer */ | |
int main() { | |
char man[PROP_VALUE_MAX + 1], mod[PROP_VALUE_MAX + 1]; | |
/* A length 0 value indicates that the property is not defined */ | |
int lman = __system_property_get("ro.product.manufacturer", man); | |
int lmod = __system_property_get("ro.product.model", mod); | |
int len = lman + lmod; | |
char *pname = NULL; | |
if (len > 0) { | |
pname = malloc(len + 2); | |
snprintf(pname, len + 2, "%s/%s", lman > 0 ? man : "", lmod > 0 ? mod : ""); | |
} | |
printf("[device]: [%s]\n", pname ? pname : "N/A"); | |
if (pname) free(pname); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment