理论部分
1、每个设备都有一个唯一序列号,Android设备也不例外,PC上用Mac地址
实践部分
1、核心代码:
Secure.getString(getContentResolver(),Secure.ANDROID_ID);
2、一个小案例:
main.xml
http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:id="@+id/tvId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.widget.TextView;
public class AndroididActivity extends Activity {
TextView tvId = null;
String androidId = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
androidId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
tvId = (TextView)findViewById(R.id.tvId);
tvId.setText(androidId);
tvId.setTextSize(30.0f);
}
}