<meta-data
android:name="com.google.android.gms"
android:value="AIzaSyDnmz6-aXCaLI7KCXYht13szZmShoyG2S4" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />那一段字符串就是API Key。这样就把项目和开发者账户关联在一起了。如果已经配置好了这个信息,还想用到google services的其它功能如:Googleplus、google analytics等,只需要授权开通API即可。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;
}并调用这个方法private static final String TAG = "Umeng";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.e(TAG, "json" +getDeviceInfo(this));
}由于获取设备信息,是需要权限的,所以还需要配置权限信息:<uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />运行完后,在控制台,过滤一下,就可以获得设备信息,如下:
12-23 09:19:53.424: E/Umeng(1357): json<span style="color:#FF6666;">{"device_id":"000000000000000","mac":"08:00:27:80:7c:2a"}</span>这样,一切准备工作就ok了!原文地址:http://blog.csdn.net/z18789231876/article/details/42125763