Android Get all device information

Source: Internet
Author: User

Private Static FinalString file_memory = "/proc/meminfo"; Private Static FinalString file_cpu = "/proc/cpuinfo";/*** Get IMEI * *@return     */     Public Static FinalString Getimei (context context) {Telephonymanager TM=(Telephonymanager) context. Getsystemservice (Context.telephony_service); String IMEI=Tm.getdeviceid (); if(IMEI = =NULL|| Imei.equals ("000000000000000")) {            return"0"; }        returnIMEI; }    /*** Get Serial number * *@paramContext *@return     */     Public Static FinalString Getserinumber (context context) {Telephonymanager TM=(Telephonymanager) context. Getsystemservice (Context.telephony_service); String SN=Tm.getsimserialnumber (); returnSN; }    /*** Get IMSI * *@return     */     Public Static FinalString Getimsi (context context) {Telephonymanager TM=(Telephonymanager) context. Getsystemservice (Context.telephony_service); String IMSI=Tm.getsimserialnumber (); if(IMSI = =NULL|| Imsi.equals ("000000000000000")) {            return"0"; }        returnIMSI; }/*** <p> * Phone available memory size * </p> * *@paramContext *@return     * @authorChenfei * @date 2013-1-4*/     Public Static LongGetfreemem (Context context) {Activitymanager Manager=(Activitymanager) context. Getsystemservice (Activity.activity_service); Memoryinfo Info=NewMemoryinfo ();        Manager.getmemoryinfo (info); LongFree = info.availmem/1024/1024; returnFree ; }    /*** <p> * Phone overall memory size * </p> * *@paramContext *@return     * @authorChenfei * @date 2013-1-4*/     Public Static LongGettotalmem (Context context) {Try{FileReader fr=NewFileReader (file_memory); BufferedReader BR=NewBufferedReader (FR); String text=Br.readline (); String[] Array= Text.split ("\\s+"); returnLong.valueof (array[1])/1024; } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); }        return-1; }    /*** <p> * Phone CPU model * </p> * *@return     * @authorChenfei * @date 2013-1-4*/     Public StaticString Getcpuinfo () {Try{FileReader fr=NewFileReader (FILE_CPU); BufferedReader BR=NewBufferedReader (FR); String text=Br.readline (); String[] Array= Text.split (": \\s+", 2); returnArray[1]; } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); }        return NULL; }    /*** <p> * phone model such as XT702 * </p> * *@return     * @authorChenfei * @date 2013-1-4*/     Public StaticString Getmodelname () {returnBuild.model; }    /*** <p> * Phone manufacturer name * </p> * *@return     * @authorChenfei * @date 2013-1-4*/     Public StaticString Getmanufacturername () {returnBuild.manufacturer; }/*** <p> * mobile OS version * </p> * *@return     * @authorChenfei * @date 2013-1-4*/     Public StaticString getsoftsdkversion () {returnBuild.VERSION.RELEASE;//Firmware/os Version number    }    /*** Get bluetooth MAC address * *@return     */     Public Staticstring Getbluetoothaddress () {string address=Bluetoothadapter.getdefaultadapter (). getaddress (); returnAddress = =NULL? "": Address; }    /*** Get access to the Internet * *@paramMcontext *@return     */     Public Staticstring Getnettype (Context mcontext) {String NetType= ""; Connectivitymanager ConnectionManager=(Connectivitymanager) mcontext. Getsystemservice (Context.connectivity_service); Networkinfo Info=Connectionmanager.getactivenetworkinfo (); if(NULL! = Info &&info.isavailable ()) {NetType=Info.gettypename (); }        returnNetType; }    /*** Determine if the network connection is available * *@paramMcontext *@return     */     Public Static BooleanGetnetisvali (Context mcontext) {if(Mcontext! =NULL) {Connectivitymanager Mconnectivitymanager=(Connectivitymanager) mcontext. Getsystemservice (Context.connectivity_service); Networkinfo Mnetworkinfo=Mconnectivitymanager. Getactivenetworkinfo (); if(Mnetworkinfo! =NULL) {                returnmnetworkinfo.isavailable (); }        }        return false; }    /*** Get carrier information * *@paramMcontext *@return     */     Public Staticstring Getnetextrainfo (Context mcontext) {String netextrainfo= ""; Telephonymanager mTm=(Telephonymanager) mcontext. Getsystemservice (Context.telephony_service); if(mtm.getsimstate () = =Telephonymanager.sim_state_ready) {Netextrainfo=Mtm.getsimoperator (); if(NULL!=netextrainfo) {                if(Netextrainfo.equals ("46000")                        || Netextrainfo.equals ("46002")                        || Netextrainfo.equals ("46007")) {                    //China MobileNetextrainfo = "China Mobile"; } Else if(Netextrainfo.equals ("46001")) {                    //China UnicomNetextrainfo = "China Unicom"; } Else if(Netextrainfo.equals ("46003")) {                    //China TelecomNetextrainfo = "China Telecom"; } Else{netextrainfo= "Other"; }            }        }        returnNetextrainfo; }    /*** Get wifi address * *@paramContext *@return     */     Public StaticString Getwifimac (context context) {Wifimanager WiFi=(Wifimanager) context. Getsystemservice (Context.wifi_service); Wifiinfo Info=Wifi.getconnectioninfo (); String Wifimac=info.getmacaddress (); returnWifimac; }    /*** Get Phone number * *@paramContext *@return     */     Public StaticString Getphonenumber (context context) {Telephonymanager mtelephonymgr; Mtelephonymgr=(Telephonymanager) context. Getsystemservice (Context.telephony_service); returnMtelephonymgr.getline1number (); }

Temporarily write so much first, some models get to get some properties such as phone number, Bluetooth address, serial number. Note that the appropriate permissions are added to the manifest when using

Android Get all device information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.