LoginSignup
4
4

More than 5 years have passed since last update.

AndroidでSIMカードが刺さっているかどうかを取得する

Posted at

AndroidでSIMカードが刺さっているかどうかを確認したかったので、やり方を調べてみました。
以下のコードでSIMカードの状態が取得できます。

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int simState = telephonyManager.getSimState();

getSimState()は以下のいずれかの値を返します。

いろいろな値がありますが、シンプルにSIMカードが刺さっていて、それが利用できるかどうかを判別したいだけならSTATE_READYであるかどうかを判別すればOKです。

TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int simState = telephonyManager.getSimState();
if (simState == TelephonyManager.SIM_STATE_READY) {
  // SIMカードが刺さっていて利用可能な状態
}
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4