---
title: "andriod获取本机电话号码及手机型号"
author: "ralphr"
date: "2011-08-23T09:13:41Z"
tags: []
categories: ["Web前端"]
slug: "andriod"
draft: false
lastmod: "2011-08-23T09:13:41Z"
id: 1155561
url: "https://wwww.iteye.com/blog/1155561"
---

**1、统计手机的型号和版本号，利用程序可以获取到相应的手机信息**

public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
        TextView textView = (TextView) findViewById(R.id.text);  
        textView.setText("Product Model: " + android.os.Build.MODEL + ","  
                + android.os.Build.VERSION.SDK + ","  
                + android.os.Build.VERSION.RELEASE);  
    }

**2、获取本机电话号码：**

TelephonyManager phoneMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY\_SERVICE);

      Systerm.out.print("手机号码为："+phoneMgr.getLine1Number())；

注：根据Android的安全机制，在使用TelephonyManager时，必须在AndroidManifest.xml中添加&lt;uses-permission android:name="READ\_PHONE\_STATE" /&gt; 否则无法获得系统的许可。  
　　

获取手机型号 Build.MODEL

private void loadPhoneStatus(){

TelephonyManager phoneMgr=(TelephonyManager)this.getSystemService(Context.TELEPHONY\_SERVICE);

      Systerm.out.print("手机型号为："+Build.MODEL); //手机型号  
      Systerm.out.print("本机电话号码为："+phoneMgr.getLine1Number());//本机电话号码  
     Systerm.out.print("SDK版本号为："+Build.VERSION.SDK);//SDK版本号  
     Systerm.out.print("版本号为："+Build.VERSION.RELEASE);//Firmware/OS 版本号  
}

**3、ip地址：**  
public String getLocalIpAddress()  
    {  
        try  
        {  
            for (Enumeration&lt;NetworkInterface&gt; en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)  
            {  
               NetworkInterface intf = en.nextElement();  
               for (Enumeration&lt;InetAddress&gt; enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)  
               {  
                   InetAddress inetAddress = enumIpAddr.nextElement();  
                   if (!inetAddress.isLoopbackAddress())  
                   {  
                       return inetAddress.getHostAddress().toString();  
                   }  
               }  
           }  
        }  
        catch (SocketException ex)  
        {  
            Log.e("WifiPreference IpAddress", ex.toString());  
        }  
        return null;  
    }