获得Android设备的唯一序列号(一)

来源:互联网 发布:java 多线程列子 编辑:程序博客网 时间:2024/05/23 22:17

理论部分

1、每个设备都有一个唯一序列号,Android设备也不例外,PC上用Mac地址

实践部分

1、核心代码:

     Secure.getString(getContentResolver(),Secure.ANDROID_ID);

2、一个小案例:

    main.xml 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvId"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>

 

 

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);
 }
}

原创粉丝点击