从网上找了一个获取序列号的代码,为何不好使?真机上取的也是0000000000
package android.test;import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;import android.app.Activity;
import android.os.Bundle;
import android.content.ContentResolver;
import android.content.Intent;   
import android.net.Uri;   
//import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;public class test extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn01 = (Button) findViewById(R.id.button1);
        btn01.setOnClickListener(A);    }
        public OnClickListener A = new OnClickListener(){
        @Override
         
        public void onClick(View v) {
        String strcpu=getCPUSerial();
         //final Uri uri = "http://suokui1234.gicp.net/default.aspx?cpu="+Uri.parse(strcpu);           
          //  final Intent it = new Intent(Intent.ACTION_VIEW, uri); 
            //startActivity(it); 
            EditText text01 = (EditText) findViewById(R.id.editText1);
            text01.setText(strcpu);        }
    };
    public void onRestart()   
    {   
        super.onRestart();           
        System.exit(0);   
  
    }   
    /**
    
     * 获取CPU序列号
     
     * 
     
     * @return CPU序列号(16位)
     
     * 读取失败为"0000000000000000"
     
     */
     
   public static String getCPUSerial() {
     
           String str = "", strCPU = "", cpuAddress = "0000000000000000";
     
           try {
     
                   //读取CPU信息
     
                   //Process pp = Runtime.getRuntime().exec("cat /proc/cpuinfo");
               Process pp = Runtime.getRuntime().exec("system/proc/cpuinfo");
                   InputStreamReader ir = new InputStreamReader(pp.getInputStream());
     
                   LineNumberReader input = new LineNumberReader(ir);
     
                   //查找CPU序列号
     
                   for (int i = 1; i < 500; i++) {
     
                           str = input.readLine();
   
                           if (str != null) {
     
                                   //查找到序列号所在行
     
                                   //if (str.indexOf("Serial") > -1) {
     
                                           //提取序列号
     
                                           strCPU = str.substring(str.indexOf(":") + 1,
     
                                                           str.length());
     
                                           //去空格
     
                                           //cpuAddress = strCPU.trim();
                                           cpuAddress+= str.trim();
                                          // break;
     
                                   //}
     
                           }else{
     
                                   //文件结尾
     
                                   break;
     
                           }
     
                   }
     
           } catch (IOException ex) {
     
                   //赋予默认值
     
                   ex.printStackTrace();
     
           }
        
          // ContentResolver arg0 = getContentResolver().query(uri , null, null, null,null);
//String t=android.provider.Settings.System.getString(arg0, "android_id=");
           //Log.i("huilurry","android_id="+t);
          // return t;
           return cpuAddress;
           //return "aaabbbcccddd";
     
   }  
}

解决方案 »

  1.   

    我也遇到这个问题了 LZ解决木有哇o(>﹏<)o
      

  2.   

    我也要取平板电脑的序列号,用了很多种方法都不行,Mac地址能取到。
      

  3.   

    取mac方法: private String getLocalMacAddress() {   
            WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);   
            WifiInfo info = wifi.getConnectionInfo();   
            return info.getMacAddress();   
        }