问题描述
我是Java和Android的新手,我需要基本上从我的设备中检索硬件序列号。
我试过以下内容:
I'm new with Java and android and i need to basically retrieve hardware serial number from my device.I've tried the following:
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;
}
我遇到以下错误:
java:40:错误:找不到符号
I'm facing the following error:java:40: error: cannot find symbol
SerialNumber=android.os.Build.getserial;
^
symbol:variable getserial
location:class Build
1错误
:compileDebugJavaWithJavac失败
symbol: variable getserial location: class Build1 error:compileDebugJavaWithJavac FAILED
我在那里错过了什么?
如果我返回androidid(MODEL)它然后工作正常。
也许有关于班级声明的事情?
What am i missing there?If I return androidid (MODEL) it then works OK.Maybe something to have with the class declaration??
提前感谢您的宝贵帮助
Elie
Thanks in advance for your precious helpElie
推荐答案
您正在使用错误的getSerial。它的方法不可变,可从API 26或更高版本获得。对于旧版本,请使用 Build.SERIAL
You are using getSerial incorrectly. Its a method not variable and available from API 26 or higher. For older versions, use Build.SERIAL
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
// Todo Don't forget to ask the permission
SerialNumber = Build.getSerial();
}
else
{
SerialNumber = Build.SERIAL;
}
确保您在调用 READ_PHONE_STATE 权限code> getSerial()。否则你的应用程序将崩溃。
Make sure you have READ_PHONE_STATE permission before calling getSerial()
. Otherwise your app will crash.
检查用于询问权限。
这篇关于棉花糖上的getSerial()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!