facebook twitter hatena line email

Android/端末id取得

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

必要以上に取得しない方がいいが、取得したい場合は以下の用に取得可能。

  • AndroidManifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
  • AndroidInfoUtil.java
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import android.content.Context;
import android.util.Log;
// 必須:<uses-permission android:name="android.permission.READ_PHONE_STATE" />
public class AndroidInfoUtil {
  public static void debug(Context context) {
    // android_id
    String android_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
    Log.d("build", "android_id:" + android_id);

    TelephonyManager mTelephonyMgr =
    (TelephonyManager)context.getSystemService(context.TELEPHONY_SERVICE);

    // IMEI
    String imei = mTelephonyMgr.getDeviceId();
    Log.d("build", "imei:" + imei);
    // 電話番号
    String phoneNumber=mTelephonyMgr.getLine1Number();
    Log.d("build", "phoneNumber:" + phoneNumber);

    // 端末ソフトウェアバージョン
    String softwareVer = mTelephonyMgr.getDeviceSoftwareVersion();
    Log.d("build", "softwareVer:" + softwareVer);

    // ICCID
    String simSerial = mTelephonyMgr.getSimSerialNumber();
    Log.d("build", "simSerial:" + simSerial);

    // IMSI
    String subscriberId = mTelephonyMgr.getSubscriberId();
    Log.d("build", "subscriberId:" + subscriberId);
  }
  public static String getSubscriberId(Context context) {
    TelephonyManager mTelephonyMgr =
    (TelephonyManager)context.getSystemService(context.TELEPHONY_SERVICE);
    // IMSI
    String subscriberId = mTelephonyMgr.getSubscriberId();
    Log.d("build", "subscriberId:" + subscriberId);
    return subscriberId;
  }
}

参考

http://ameblo.jp/wonder-perfume/entry-10839101720.html