Created
March 10, 2014 07:05
-
-
Save oa414/9460642 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://www.umeng.com/test_devices | |
| 获取deviceid | |
| 加入以下权限 | |
| <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> | |
| <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission> | |
| <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission> | |
| 代码 | |
| 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); | |
| Log.d("TAG", 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); | |
| } | |
| Log.d("TAG", json.toString()); | |
| return json.toString(); | |
| }catch(Exception e){ | |
| e.printStackTrace(); | |
| } | |
| return null; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment