| |
Membre enregistré 10 messages |
|
| Posté le 20 novembre 2017 - 11:12 |
Bonjour à tous les développeurs, Je voudrais extraire le numéro de série hardware d'un appareil Android. L'OS est Android 6.0 Marshmallow. J'ai trouvé la librairie java suivante: String getSerial () J'ai créé une procédure dans mon Windev 22 comme suit:
import android.content.*; import android.os.Build; public static String recup_android() { String androidid; String SerialNumber;
androidid=android.os.Build.MODEL; SerialNumber=android.os.Build.getserial; return SerialNumber; }
La compilation me génère une erreur comme suit:
Ligne de commande : "C:\Program Files\Java\jdk1.8.0_40\bin\java.exe" "-Dorg.gradle.appname=C:\Mes Projets Mobile\TEST\Android\Generation" -classpath "C:\WINDEV Mobile 22\Personnel\Android\Gradle\lib\gradle-launcher-2.14.1.jar" org.gradle.launcher.GradleMain assembleDebug -b "C:\Mes Projets Mobile\TEST\Android\Generation\build.gradle"
Erreur retournée :
:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.). C:\Mes Projets Mobile\TEST\Android\Generation\src\com\atrium_id\wdgen\GWDCPProceduresGlobales.java:70: error: class, interface, or enum expected } ^ 1 error :compileDebugJavaWithJavac FAILED
Par contre si je fais return androidid; et que j'enlève le numéro de série c'est OK.
Quelqu'un a une idée s'il vous plaît??
Merci
EB |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 10 messages |
|
| Posté le 20 novembre 2017 - 11:23 |
Pardon: L'erreur précédente était due aux accolades... Mais J'ai l'erreur cannot find symbol !!! Merci pour votre aide.
Echec de la création de l'application Android <C:\Mes Projets Mobile\TEST\Exe\TEST.apk>.
Ligne de commande : "C:\Program Files\Java\jdk1.8.0_40\bin\java.exe" "-Dorg.gradle.appname=C:\Mes Projets Mobile\TEST\Android\Generation" -classpath "C:\WINDEV Mobile 22\Personnel\Android\Gradle\lib\gradle-launcher-2.14.1.jar" org.gradle.launcher.GradleMain assembleDebug -b "C:\Mes Projets Mobile\TEST\Android\Generation\build.gradle"
Erreur retournée :
:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.). C:\Mes Projets Mobile\TEST\Android\Generation\src\com\test_id\wdgen\GWDCPProceduresGlobales.java:40: error: cannot find symbol SerialNumber=android.os.Build.getserial; ^ symbol: variable getserial location: class Build 1 error :compileDebugJavaWithJavac FAILEDMessage modifié, 20 novembre 2017 - 11:26 |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 32 messages |
|
| Posté le 20 novembre 2017 - 11:34 |
Bonjour,
Pour moi la bonne syntaxe serait:
SerialNumber=android.os.Build.getserial();
Bon dév
-- Laurent P |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 10 messages |
|
| Posté le 20 novembre 2017 - 11:52 |
Merci beaucoup pour ton attention Laurent mais non! J'ai de nouveau: java:40: error: cannot find symbol SerialNumber=android.os.Build.getserial(); Quelqu'un d'autres a une idée? JE me demande si ce n'est pas lié à la déclaration static ? JE devrais peut être déclarer une class? |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 2 682 messages |
|
| Posté le 20 novembre 2017 - 12:16 |
Bonjour,
C'est SerialNumber=android.os.Build.getSerial(); avec un "S" majuscule. Java est sensible à la casse
-- Cordialement,
Philippe SAINT-BERTIN Géode Informatique |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 10 messages |
|
| Posté le 20 novembre 2017 - 12:29 |
Merci Philippe. Mais je n'ai décidément pas de chance 
java:32: error: cannot find symbol SerialNumber=android.os.Build.getSerial(); ^ symbol: method getSerial() location: class Build 1 error :compileDebugJavaWithJavac FAILED |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 2 682 messages |
|
| Posté le 20 novembre 2017 - 14:03 |
As tu testé ton code sous Android studio pour vérifier que ca fonctionne ?
-- Cordialement,
Philippe SAINT-BERTIN Géode Informatique |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 10 messages |
|
| Posté le 20 novembre 2017 - 14:04 |
JE vous remercie pour vos contributions. Mais en fait, Build.SERIAL renvoie le numéro de série de l'appareil dans mon cas. JE pensais qu'avec un Marshmallow ou nougat, ce serait plus le cas, mais en fait si ça fonctionne  Merci encore et bonne semaine à vous. EB |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 948 messages |
|
| Posté le 20 novembre 2017 - 16:17 |
Bonjour, Essayez ceci (fonctionne sur Samsung Note 3 API-21)
//-------------------------------------------------------------------------------- // see : https://developer.android.com/reference/android/os/Build.html#getSerial() // Renvois une chaine avec des informations sur la machine //-------------------------------------------------------------------------------- import android.os.Build; import android.os.Build.VERSION; import android.provider.Settings.Secure; import android.content.pm.*; import android.content.Context; import android.provider.Settings; import java.lang.reflect.Field;
public static String getInfosDevice() { String InfosDevice = ""; String android_id = ""; String osName = ""; Context myContext = getContexteApplication(); android_id = Secure.getString(myContext.getContentResolver(), Secure.ANDROID_ID); Field[] fields = Build.VERSION_CODES.class.getFields(); osName = fields[Build.VERSION.SDK_INT + 1].getName(); InfosDevice = Build.MANUFACTURER + "\t"; // samsung (ro.product.manufacturer) InfosDevice += Build.MODEL + "\t"; // SM-N9005 (ro.product.model) InfosDevice += Build.SERIAL + "\t"; // "d4364aba" (ro.serialno) InfosDevice += Build.VERSION.SDK_INT + "\t"; // 21 -> API-Level (ro.build.version.sdk) InfosDevice += Build.VERSION.RELEASE + "\t"; // 5.0 (ro.build.version.release) InfosDevice += Build.DISPLAY + "\t"; // LRX21V.N9005XXSGBPL6 (ro.build.display.id) InfosDevice += Build.ID + "\t"; // LRX21V (ro.build.id) InfosDevice += android_id + "\t"; // 546259d7609efccc (net.hostname) InfosDevice += osName; // LOLLIPOP // return InfosDevice; } |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 948 messages |
|
| Posté le 20 novembre 2017 - 16:20 |
ou cette méthode
import java.lang.Object;
public static String getSerialNumber() { String serial_no = null; try { Class> c = Class.forName("android.os.SystemProperties"); serial_no = (String) c.getMethod("get", String.class).invoke(c, "ril.serialnumber"); // ro.serialno --> "d4364aba" identique à Build.SERIAL // sys.serialnumber --> "" // ril.serialnumber --> "R38F10MWL9K" bingo ! } catch (Exception e) { System.out.println("Some error occured : " + e.getMessage()); } return serial_no; } |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 948 messages |
|
| Posté le 20 novembre 2017 - 16:22 |
3ème et dernière méthode :
//----------------------------------------------------------------------------- // Renvois la valeur d'une propriété du terminal. // Pour en avoir la liste exécuter sous cmd : adb shell getprop //----------------------------------------------------------------------------- // [dhcp.wlan0.gateway]: [192.168.1.1] // [dhcp.wlan0.ipaddress]: [192.168.1.13] // [dhcp.wlan0.leasetime]: [604800] // [dhcp.wlan0.mask]: [255.255.255.0] // [dhcp.wlan0.mtu]: [] // [dhcp.wlan0.pid]: [6020] // [dhcp.wlan0.reason]: [BOUND] // [dhcp.wlan0.result]: [ok] // [dhcp.wlan0.roaming]: [0] // [dhcp.wlan0.server]: [192.168.1.1] // ...................................... // Ex : getSytemProperty("ril.serialnumber") -> numéro de série du terminal //----------------------------------------------------------------------------- import java.lang.Process; import java.lang.Runtime; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import android.util.Log;
public static String getSystemProperty(String propName) { String TAG = "PhPa"; String line; BufferedReader input = null; try { Process p = Runtime.getRuntime().exec("getprop " + propName); input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); line = input.readLine(); input.close(); } catch (IOException ex) { Log.e(TAG, "Lecture de la propriété : " + propName + ", impossible", ex); return null; } finally { if (input != null) { try { input.close(); } catch (IOException e) { Log.e(TAG, "Erreur getSystemProperty", e); } } } return line; } |
| |
| |
| | | |
|
| | |
| |
| Posté le 09 mai 2019 - 10:56 |
Merci Philippe 
La première procédure fonctionne très bien pour moi (Sur un Honeywell EDA51) La deuxième ne renvoyait rien et je n'ai pas essayé la troisième.
Jamais aucune alerte à la compilation. (Je suis en Windev Mobile 21)
Je ne pense pas être le seul à avoir utilisé tes procédures et je déplore d'être le premier à te remercier. Les usages se perdent...  |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 7 messages |
|
| Posté le 26 juillet 2022 - 09:59 |
Merci Philippe 👌 En 2022 Vous aidez la communauté par votre intervention. Mille merci ! 🙏🏼🙏🏼🙏🏼🙏🏼 |
| |
| |
| | | |
|
| | |
| |
| Posté le 16 décembre 2025 - 14:49 |
bonjour, existe-t-il une solution à partir de android 14? merci |
| |
| |
| | | |
|
| | |
| |
Membre enregistré 999 messages |
|
| Posté le 16 décembre 2025 - 21:09 |
CJulien Launaz a écrit :
bonjour, existe-t-il une solution à partir de android 14? merci Ce n'est plus possible depuis la version 10, on ne peut qu'avoir un UniqueID lié a ton application, mais si tu désinstalle l'uniqueID change
NOTE 2021/01/08: As of Android 10 (API level 29), there's no way for non-system and non-carrier apps to get the device's serial number, not even by calling the new Build.getSerial() method with the READ_PHONE_STATE permission, since per the docs it'll always either return Build.UNKNOWN (API < 29) or throw a SecurityException (API >= 29). This means that the code below might not work on some devices running Android 10+, due to changes in the Android OS itself and AFAIK there's no work around. See this official guide to migrate from using the device's serial number ; the Settings.Secure.ANDROID_ID might also be a good replacement. Also read the comments to see how other people are dealing with this problem, maybe someone has found a solution that will help you.
Ndrj |
| |
| |
| | | |
|
| | |