android设备号是唯一的deviceID;
TelephonyManager
这个管理类中包含很多属性,
TelephonyManager tm= (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE); listValues.add(tm.getDeviceId());//获取设备编号 listValues.add(tm.getSimCountryIso());//获取SIM卡国别 listValues.add(tm.getSimSerialNumber());//获取SIM卡序列号 listValues.add(simState[tm.getSimState()]);//获取SIM卡状态 listValues.add((tm.getDeviceSoftwareVersion()!=null?tm.getDeviceSoftwareVersion():"未知")); //获取软件版本 listValues.add(tm.getNetworkOperator());//获取网络运营商代号 listValues.add(tm.getNetworkOperatorName());//获取网络运营商名称 listValues.add(phoneType[tm.getPhoneType()]);//获取手机制式 listValues.add(tm.getCellLocation().toString());//获取设备当前位置另外网络的判断,判断是否连接上了网络class MyBroadcast extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // mobile 3G Data Network NetworkInfo mobile = CM .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); // wifi net NetworkInfo wifi = CM.getNetworkInfo(ConnectivityManager.TYPE_WIFI); try { // 判断网络是否连接 // 如果3G网络和wifi网络都未连接,且不是处于正在连接状态 则进入Network Setting界面 由用户配置网络连接 if (!mobile.isConnected() && !wifi.isConnected()) { signals.setVisibility(View.GONE); signals.setBackgroundResource(R.drawable.well); tv_nettype.setVisibility(0);// 设置可见 tv_nettype.setText("未连接网络,请连接可用网络!"); tv_signal.setVisibility(View.VISIBLE); tv_signal.setText("无信号"); tv_netname.setVisibility(View.VISIBLE); tv_netname.setText("无名称"); dispaly_ping.setVisibility(View.GONE); hint.setVisibility(View.GONE);// tv_setting.setText("当前未连接任何网络是否重置?");// tv_signal.setVisibility(View.GONE);// tv_setting.setOnClickListener(new OnClickListener() { // @Override// public void onClick(View v) { // startActivity(new Intent(// Settings.ACTION_WIRELESS_SETTINGS));// 进入无线网络配置界面// }// }); } else { // 网络已经连接 CM = (ConnectivityManager) ActivityAppList.this .getSystemService(Context.CONNECTIVITY_SERVICE); //获得wifi管理的服务 wifiManager = (WifiManager) ActivityAppList.this .getSystemService(Context.WIFI_SERVICE); //获取网络服务的 NetworkInfo networkInfo = CM.getActiveNetworkInfo(); //获取网络类型 int nettype = networkInfo.getType(); //如果是wifi if (nettype == ConnectivityManager.TYPE_WIFI) { // 当前使用的是 tv_nettype.setVisibility(0); tv_nettype.setText("当前网络连接类型:WIFI"); tv_netname.setVisibility(0); signals.setVisibility(View.VISIBLE); tv_signal.setVisibility(View.VISIBLE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); int speed = wifiInfo.getLinkSpeed();// 获取连接速度 int ipaddress = wifiInfo.getIpAddress(); // 获取ip地址 int netid = wifiInfo.getNetworkId(); // 获取网络id int netrssi = wifiInfo.getRssi();// 信号的强度 String macaddress = wifiInfo.getMacAddress();// 取得设备的mac地址 String netname = wifiInfo.getSSID(); // 获取网络名称 getConfiguration(); System.out .println(""); removeWifi("CMCC"); String wifiname=wifiInfo.getSSID(); int wifiId=0; if ("CMCC".equals(wifiname)) { wifiId=wifiInfo.getNetworkId(); System.out .println(wifiId+"^^^^^^^"); wifiManager.removeNetwork(wifiId); }else if("ChinaNet".equals(wifiname)){ wifiId=wifiInfo.getNetworkId(); System.out .println(wifiId+"^^^^^^^"); wifiManager.removeNetwork(wifiId); }else if("ChinaUnicom".equals(wifiname)){ wifiId=wifiInfo.getNetworkId(); System.out .println(wifiId+"^^^^^^^"); wifiManager.removeNetwork(wifiId); }else if("CMCC-EDU".equals(wifiname)){ wifiId=wifiInfo.getNetworkId(); System.out .println(wifiId+"^^^^^^^"); } System.out.println(netid+"net====="); tv_netname.setText("网络名称:" + netname); if (netrssi < 0 && netrssi > -50) { signals.setBackgroundResource(R.drawable.good); tv_signal.setText("网络信号强度:" + "好"); } else if (netrssi < -50 && netrssi > -70) { signals.setBackgroundResource(R.drawable.well); tv_signal.setText("网络信号强度:" + "一般"); } else if (netrssi < -70) { tv_signal.setText("网络信号强度:" + "较差"); signals.setBackgroundResource(R.drawable.bad); } } else { tv_signal.setVisibility(View.VISIBLE); signals.setVisibility(View.VISIBLE); CM = (ConnectivityManager) ActivityAppList.this .getSystemService(Context.CONNECTIVITY_SERVICE); //网络类型为:数据连接 tv_nettype.setVisibility(View.VISIBLE); tv_nettype.setText("当前网络类型:数据连接"); tv_netname.setVisibility(View.GONE); tel.listen(new PhoneStateMonitor(), PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_SERVICE_STATE); } } } catch (Exception e) { // TODO: handle exception } } 获取 手机型号 phoneName = Build.MANUFACTURER + "-" + Build.MODEL;获取SN号package com.innofidei.createsn;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import com.innofidei.read.ReadSXTBChannel;import android.app.Activity;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.content.Intent;import android.os.Bundle;import android.provider.Settings.Secure;import android.telephony.TelephonyManager;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;public class MainActivity extends Activity { private Button btn; private String path="mnt/sdcard/xxx.txt"; private TelephonyManager tm; String sn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn=(Button) findViewById(R.id.btn1); tm= (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE); //sn=tm.getDeviceId(); sn = Secure.getString(MainActivity.this.getContentResolver(), Secure.ANDROID_ID); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //生成在SDcard sn号 File file=new File(path); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } BufferedReader br; FileWriter fw; FileReader fr; BufferedWriter bw; StringBuffer sb = new StringBuffer(); try { fw = new FileWriter(file);// 初始化输出流 bw = new BufferedWriter(fw);// 初始化输出字符流 bw.write(sn);// 写文件 bw.flush(); bw.close(); fw.close(); fr = new FileReader(file);// 初始化输入流 br = new BufferedReader(fr);// 初始化输入字符流 sb.append(br.readLine().toString());// 按行读文件 System.out.println("文件内容是:" + sb); if (sb!=null) { new AlertDialog.Builder(MainActivity.this) .setTitle(String.valueOf("获取的SN号")) .setMessage(String.valueOf("SN号已经获取到“,sb) .setPositiveButton("确 定", new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog, int which) { } }).show(); Toast.makeText(MainActivity.this, "SN号初始化完成"+sb.toString(), Toast.LENGTH_LONG).show(); } br.close(); fr.close(); } catch (Exception e) { e.printStackTrace(); } } else { } }catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }}