Android get build and memory, resolution and other information

Source: Internet
Author: User



Package Com.zms.getdeviceinfo;import Android.app.activitymanager;import Android.content.context;import Android.net.wifi.wifiinfo;import Android.net.wifi.wifimanager;import Android.os.build;import Android.support.v7.app.actionbaractivity;import Android.os.bundle;import Android.telephony.TelephonyManager; Import Android.text.format.formatter;import Android.util.displaymetrics;import Android.view.menu;import Android.view.menuitem;import Android.widget.textview;import Java.io.bufferedreader;import Java.io.FileReader; Import Java.io.ioexception;import Java.util.timezone;public class Main extends Actionbaractivity {private TextView TvI    Nfo        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.main);        Tvinfo = (TextView) Findviewbyid (r.id.tvinfo); Tvinfo.settext (getbuildinfo (0) + getdisplayinfo (0) + gettelephonystate (0) + gettimezoneinfo () + Gethardware    Info (0));  }    /**   * @param type 0-all,1-model,2-versionrelease,other-error. * @return String */private string getbuildinfo (int type) {string model = Build.model;//Model String        Versionrelease = Build.VERSION.RELEASE;        String versionsdk = Build.VERSION.SDK;        String versionincremental = Build.VERSION.INCREMENTAL;        String brand = Build.brand;        String id = build.id;        String manufacturer = Build.manufacturer;        String hardware = Build.hardware;        String Product = build.product;        String Cpuabi = Build.cpu_abi;        String cpuABI2 = Build.cpu_abi2;        String fingerprint = Build.fingerprint;        String board = Build.board;        String serial = build.serial;        String user = Build.user;                    if (type = = 0) {return "model:" + model + "\nversionrelease:" + versionrelease + "\NVERSIONSDK:" + VERSIONSDK + "\nversionincremental:" + versionincremental + "\nbrand:" + Brand + "\nid: "+ ID +" \nmanufacturer: "+ Manufacturer +" \nhardware: "+ hardware +" \nproduct: "+ Product +" \ncpu ABI: "+ Cpuabi +" \NCPUABI2: "+ cpuABI2 +" \nfingerprint: "+ fingerprint +" \nboard: "+ board +" \nseri        AL: "+ serial +" \nuser: "+ user +" \ n ";        } else if (type = = 1) {return "model" + model + "\ n");        } else if (type = = 2) {return "versionrelease:" + versionrelease + "\ n";        } else {return "[Getbuildinfo ERR]"; }} private String gethardwareinfo (int type) {Wifimanager Wifimanager = (wifimanager) getsystemservice (Conte Xt.        Wifi_service);        Wifiinfo wifiinfo = Wifimanager.getconnectioninfo ();        String macAddress = wifiinfo.getmacaddress ();        String strcpu = "";  String[] CpuInfo = {"", ""};        1-CPU model//2-CPU frequency string[] arrayofstringcpu;            try {filereader FileReader = new FileReader ("/proc/cpuinfo"); BuffEredreader Localbufferedreader = new BufferedReader (FileReader, 8192);            STRCPU = Localbufferedreader.readline ();            ARRAYOFSTRINGCPU = Strcpu.split ("\\s+");             for (int i = 2; i < arrayofstringcpu.length; i++) {cpuinfo[0] = Cpuinfo[0] + arrayofstringcpu[i] + "";            } STRCPU = Localbufferedreader.readline ();            ARRAYOFSTRINGCPU = Strcpu.split ("\\s+");            CPUINFO[1] + = arrayofstringcpu[2];        Localbufferedreader.close ();        } catch (IOException e) {e.printstacktrace ();        }//adb shell;cat/proc/meminfo activitymanager.memoryinfo memoryinfo = new Activitymanager.memoryinfo (); Activitymanager Activitymanager = (activitymanager) this.getsystemservice (Context.activity_service)        ;        Activitymanager.getmemoryinfo (Memoryinfo);        Long mtotalmem = memoryinfo.totalmem;//0;        Long mavailmem = Memoryinfo.availmem; /* String strMemory;        String[] arrayofstringmemory;            try {filereader localfilereader = new FileReader ("/proc/meminfo");            BufferedReader localbufferedreader = new BufferedReader (Localfilereader, 8192);            Strmemory = Localbufferedreader.readline ();            Arrayofstringmemory = Strmemory.split ("\\s+");            Mtotalmem = integer.valueof (Arrayofstringmemory[1]). Intvalue () * 1024;        Localbufferedreader.close ();        } catch (IOException e) {e.printstacktrace ();        } */String totalmemory = Formatter.formatfilesize (this, mtotalmem);        String availmemory = Formatter.formatfilesize (this, mavailmem);                    if (type = = 0) {return "MacAddress:" + MacAddress + "\ncpumodel:" + cpuinfo[0] + "\ncpuclock:" +        CPUINFO[1] + "\ntotalmemory:" + totalmemory + "\navailablememory:" + availmemory + "\ n";        } else {return ""; }}/** * @param tyPE 0-all,1-deviceid,2-subscriberid,3-phonenumber,other-error. * @return String */private string gettelephonystate (int type) {Telephonymanager Telephonymanager = (teleph        Onymanager) Getsystemservice (Telephony_service);        String deviceId = Telephonymanager.getdeviceid ();        String SubscriberId = Telephonymanager.getsubscriberid ();        String PhoneNumber = Telephonymanager.getline1number (); if (type = = 0) {return "DeviceId:" + DeviceId + "\nsubscriberid:" + SubscriberId + "\nphonenumber:" + phonenum        ber + "\ n";        } else if (type = = 1) {return "DeviceId:" + DeviceId + "\ n";        } else if (type = = 2) {return "SubscriberId" + SubscriberId + "\ n";        } else if (type = = 3) {return "PhoneNumber:" + phonenumber + "\ n";        } else {return "[gettelephonystate ERR]";     }}/** * @param type 0-all,1-screenheight,2-screenwidth,other-error. * @return String */PrivaTe String getdisplayinfo (int type) {Displaymetrics displaymetrics = new Displaymetrics ();        Getwindowmanager (). Getdefaultdisplay (). Getmetrics (Displaymetrics);        int screenheight = Displaymetrics.heightpixels;        int screenwidth = Displaymetrics.widthpixels;        if (type = = 0) {return "ScreenHeight:" + screenheight + "\nscreenwidth:" + screenwidth + "\ n";        } else if (type = = 1) {return "ScreenHeight:" + screenheight + "\ n";        } else if (type = = 2) {return "ScreenWidth:" + screenwidth + "\ n";        } else {return "[gettelephonystate ERR]";        }} private String Gettimezoneinfo () {TimeZone TimeZone = Timezone.getdefault ();    Return "TimeZone:" + timezone.tostring () + "\ n"; } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the Actio        n Bar if it is present.        Getmenuinflater (). Inflate (R.menu.main, menu); RetuRN true; } @Override public boolean onoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here.  The action bar would//automatically handle clicks on the Home/up button, so long/As you specify a parent        Activity in Androidmanifest.xml.        int id = item.getitemid ();        Noinspection simplifiableifstatement if (id = = r.id.action_settings) {return true;    } return super.onoptionsitemselected (item); }}


Android get build and memory, resolution and other 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.