关闭

Android获取手机和系统版本等信息的代码

364人阅读 评论(0) 收藏 举报
分类:

有时候需要统计手机的型号和版本号,利用程序可以获取到相应的手机信息,对比两部手机发现,厂商不同,某个信息显示方式也不尽相同,具体见:

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);

获取当前应用的版本号:

   private String getVersionName() throws Exception
   {
           // 获取packagemanager的实例
           PackageManager packageManager = getPackageManager();
           // getPackageName()是你当前类的包名,0代表是获取版本信息
           PackageInfo packInfo = packageManager.getPackageInfo(getPackageName(),0);
           String version = packInfo.versionName;
           return version;
   }


获取当前系统的版本号:

        textView.setText("Product Model: " + android.os.Build.MODEL + "," 
                + android.os.Build.VERSION.SDK + "," 
                + android.os.Build.VERSION.RELEASE); 

或者:

/* 
 *
 * Build.VERSION_CODES
    1 (0x00000001)           Android 1.0             BASE
    2 (0x00000002)           Android 1.1             BASE_1_1
    3 (0x00000003)           Android 1.5             CUPCAKE
    4 (0x00000004)           Android 1.6             DONUT
    5 (0x00000005)           Android 2.0             ECLAIR
    6 (0x00000006)           Android 2.0.1          ECLAIR_0_1
    7 (0x00000007)           Android 2.1             ECLAIR_MR1
    8 (0x00000008)           Android 2.2             FROYO
    9 (0x00000009)           Android 2.3             GINGERBREAD
    10 (0x0000000a)         Android 2.3.3          GINGERBREAD_MR1
    11 (0x0000000b)         Android 3.0             HONEYCOMB
    12 (0x0000000c)         Android 3.1             HONEYCOMB_MR1
    13 (0x0000000d)         Android 3.2             HONEYCOMB_MR2*/
    /*获取当前系统的android版本号*/
    intcurrentapiVersion=android.os.Build.VERSION.SDK_INT;

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1665次
    • 积分:31
    • 等级:
    • 排名:千里之外
    • 原创:0篇
    • 转载:4篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档