标签:android blog io os java 文件 div on cti
public static String getDeviceInfo(Context context) { try{ org.json.JSONObject json = new org.json.JSONObject(); android.telephony.TelephonyManager tm = (android.telephony.TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); String device_id = tm.getDeviceId(); android.net.wifi.WifiManager wifi = (android.net.wifi.WifiManager) context.getSystemService(Context.WIFI_SERVICE); String mac = wifi.getConnectionInfo().getMacAddress(); json.put("mac", mac); if( TextUtils.isEmpty(device_id) ){ device_id = mac; } if( TextUtils.isEmpty(device_id) ){ device_id = android.provider.Settings.Secure.getString(context.getContentResolver(),android.provider.Settings.Secure.ANDROID_ID); } json.put("device_id", device_id); return json.toString(); }catch(Exception e){ e.printStackTrace(); } return null; }
ps:清单文件中需要的权限
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
标签:android blog io os java 文件 div on cti
原文地址:http://www.cnblogs.com/liuxu2014/p/4015892.html