基于JAVA代码 获取手机基本信息(本机号码,SDK版本,系统版本,手机型号)
程序员文章站
2024-03-07 20:02:09
老风格,废话不多说了,直接给大家贴java代码了。
代码如下:
package com.zzw.getphoneinfos;
import android.a...
老风格,废话不多说了,直接给大家贴java代码了。
代码如下:
package com.zzw.getphoneinfos; import android.app.activity; import android.content.context; import android.os.build; import android.os.bundle; import android.telephony.telephonymanager; import android.util.log; public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // 获取电话管理对象 telephonymanager mtelephonymanager = (telephonymanager) this.getsystemservice(context.telephony_service); // 获取手机号码 string phonenumber = mtelephonymanager.getline1number(); log.d("获取本机电话号码--->", phonenumber); // 获取手机型号 string phonemodel = build.model; log.d("获取手机型号--->", phonemodel); // 获取sdk版本 string phonesdkversion = build.version.sdk; log.d("获取sdk版本--->", phonesdkversion); // 获取系统版本 string phonereleaseversion = build.version.release; log.d("获取手机系统版本-->", phonereleaseversion); } }
不要忘记权限:
<uses-permission android:name="android.permission.read_phone_state" />
结果如图:
java android 获取手机操作系统相关信息
string phoneinfo = "product: " + android.os.build.product; phoneinfo += ", cpu_abi: " + android.os.build.cpu_abi; phoneinfo += ", tags: " + android.os.build.tags; phoneinfo += ", version_codes.base: " + android.os.build.version_codes.base; phoneinfo += ", model: " + android.os.build.model; phoneinfo += ", sdk: " + android.os.build.version.sdk; phoneinfo += ", version.release: " + android.os.build.version.release; phoneinfo += ", device: " + android.os.build.device; phoneinfo += ", display: " + android.os.build.display; phoneinfo += ", brand: " + android.os.build.brand; phoneinfo += ", board: " + android.os.build.board; phoneinfo += ", fingerprint: " + android.os.build.fingerprint; phoneinfo += ", id: " + android.os.build.id; phoneinfo += ", manufacturer: " + android.os.build.manufacturer; phoneinfo += ", user: " + android.os.build.user; // toast.maketext(this, phoneinfo, toast.length_long).show(); textview t = (textview) findviewbyid(r.id.main_phoneinfo); t.settext(phoneinfo);