"Android" gets the hardware information about the phone

Source: Internet
Author: User

Today in QQ group chat, a buddy in a treasure to buy a running memory 16G mobile phone, then I was scared to pee, so there is a program to write the actual memory of the phone read out the idea, so there is today this blog.


All information items are as shown. (Because my test machine does not interfere with the machine card, so some information will be shown as empty)



Here's the code:

Package Com.liu.chad.practicesqlite;import Android.app.activitymanager;import Android.content.context;import Android.os.bundle;import Android.support.v7.app.actionbaractivity;import Android.telephony.TelephonyManager; Import Android.text.format.formatter;import Android.util.log;import Android.widget.textview;import Java.io.bufferedreader;import Java.io.filenotfoundexception;import Java.io.filereader;import java.io.IOException;    Import Java.io.inputstream;public class Mainactivity extends Actionbaractivity {private TextView mtextview;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Mtextview = (TextView) Findviewbyid (R.ID.TEXTVIEWID);    Getphoneinfo (); }/** * Get phone info */public void Getphoneinfo () {Telephonymanager TM = (Telephonymanager) this.getsyste        Mservice (Telephony_service); String mtyb = android.os.build.brand;//mobile phone brand STRing mtype = Android.os.Build.MODEL;        Phone model String IMEI = Tm.getdeviceid ();        String IMSI = Tm.getsubscriberid (); String Numer = Tm.getline1number (); Mobile number String ServiceName = Tm.getsimoperatorname (); Carrier Mtextview.settext ("Brand:" + mtyb + "\ n" + "model:" + mtype + "\ n" + "version: Android" + Android.os.                Build.VERSION.RELEASE + "\ n" + "IMEI:" + IMEI + "\ n" + "IMSI:" + IMSI + "\ n" + "mobile phone Number:" + Numer + "\ n"        + "operator:" + serviceName + "\ n");        Mtextview.append ("Total Memory:" + gettotalmemory () + "\ n");        Mtextview.append ("Currently available memory:" + getavailmemory () + "\ n");        Mtextview.append ("CPU Name:" + getcpuname () + "\ n");        Mtextview.append ("CPU Max frequency:" + getmaxcpufreq () + "\ n");        Mtextview.append ("CPU Minimum frequency:" + getmincpufreq () + "\ n");    Mtextview.append ("CPU Current frequency:" + getcurcpufreq () + "\ n"); }/** * Get phone memory Size * * @return */private String Gettotalmemory () {string str1= "/proc/meminfo";//system memory information file String str2;        String[] arrayofstring;        Long initial_memory = 0;            try {filereader localfilereader = new FileReader (STR1);            BufferedReader localbufferedreader = new BufferedReader (Localfilereader, 8192);            STR2 = Localbufferedreader.readline ();//Read Meminfo first line, total system memory Size arrayofstring = Str2.split ("\\s+");            for (String num:arrayofstring) {log.i (str2, num + "\ t");            } initial_memory = Integer.valueof (Arrayofstring[1]). Intvalue () * 1024;//gets the total system memory, in kilobytes, multiplied by 1024 to byte        Localbufferedreader.close (); } catch (IOException e) {} return Formatter.formatfilesize (Getbasecontext (), initial_memory);//byte converted to KB or MB, memory size normalized}/** * Gets the current available memory size * * @return */private String getavailmemory () {Activityman        Ager am = (activitymanager) getsystemservice (Context.activity_service); Activitymanager.memorYinfo mi = new Activitymanager.memoryinfo ();        Am.getmemoryinfo (MI);    Return Formatter.formatfilesize (Getbasecontext (), MI.AVAILMEM);        } public static string Getmaxcpufreq () {String result = "";        Processbuilder cmd; try {string[] args = {"/system/bin/cat", "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_            Freq "};            cmd = new Processbuilder (args);            Process process = Cmd.start ();            InputStream in = Process.getinputstream ();            byte[] re = new byte[24];            while (In.read (re)! =-1) {result = result + new String (re);        } in.close ();            } catch (IOException ex) {ex.printstacktrace ();        result = "N/a";    } return Result.trim () + "Hz";        }//Get CPU Minimum frequency (unit khz) public static string Getmincpufreq () {String result = "";        Processbuilder cmd; try {string[] args = {"/system/bin/Cat ","/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq "};            cmd = new Processbuilder (args);            Process process = Cmd.start ();            InputStream in = Process.getinputstream ();            byte[] re = new byte[24];            while (In.read (re)! =-1) {result = result + new String (re);        } in.close ();            } catch (IOException ex) {ex.printstacktrace ();        result = "N/a";    } return Result.trim () + "Hz";        //real-time get CPU current frequency (unit khz) public static string Getcurcpufreq () {string result = "N/a"; try {FileReader fr = new FileReader ("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq            ");            BufferedReader br = new BufferedReader (FR);            String text = Br.readline ();        result = Text.trim () + "Hz";        } catch (FileNotFoundException e) {e.printstacktrace (); } catch (IOException e) {           E.printstacktrace ();    } return result;            public static String Getcpuname () {try {FileReader fr = new FileReader ("/proc/cpuinfo");            BufferedReader br = new BufferedReader (FR);            String text = Br.readline ();            string[] Array = Text.split (": \\s+", 2);        for (int i = 0; i < Array.Length; i++) {} return array[1];        } catch (FileNotFoundException e) {e.printstacktrace ();        } catch (IOException e) {e.printstacktrace ();    } return null; }}

The layout file is a textview, and I won't post it here.

"Android" gets the hardware information about the phone

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.