固有識別番号を取得する |
ここでは端末の固有識別番号を取得する方法を確認していきます。
端末の固有識別番号とは各端末が初期時に割り当てられるランダムの数値で、端末初期化で新たな数値に書き換えられます。ユーザー自身で書き換えられない情報なので機種固有IDの代替として使われています。 この固有識別番号の取得は「 Settings.Secure.ANDROID_ID 」から行うことができます。 AndroidIdActivity.java package goodroid.sample.androidid; import goodroid.sample.androidid.R; import android.app.Activity; import android.os.Bundle; import android.provider.Settings; import android.widget.TextView; public class AndroidIdActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // 端末の固有識別番号の取得 String androidId = Settings.Secure.getString( this.getContentResolver(), Settings.Secure.ANDROID_ID ); TextView tv = (TextView)findViewById(R.id.android_id); tv.setText("端末の固有識別番号:" + androidId); } } 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/android_id" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> 実行結果 ![]() |
7427 views | コメント:0 | 2012-06-19 |
コメント
|
|
まだこの記事にコメントはありません |