「.NET for AndroidでデバイスのSIMスロット数を取得する」の版間の差分
Administrator (トーク | 投稿記録) |
Administrator (トーク | 投稿記録) 編集の要約なし |
||
| 30行目: | 30行目: | ||
</source> | </source> | ||
[[category: Android]] | <amazon>.NET for Android</amazon> | ||
[[category: .NET for Android]] | |||
2024年10月22日 (火) 02:36時点における最新版
必要な権限[編集 | ソースを編集]
- android.permission.READ_PHONE_STATE
TelephonyManagerを使うには権限が必要です。
大雑把なコード[編集 | ソースを編集]
var telephonyManager = GetSystemService(TelephonyService) as TelephonyManager;
if (telephonyManager == null)
throw new NotSupportedException();
// API レベルに応じて SIM スロット数を取得
int simSlotCount = 0;
if (Android.OS.BuildVersionCodes.R <= Android.OS.Build.VERSION.SdkInt)
{// API Level 30 (Android 11) 以上
simSlotCount = telephonyManager.ActiveModemCount;
}
else if (Android.OS.BuildVersionCodes.M <= Android.OS.Build.VERSION.SdkInt)
{// API Level 23 (Android 6.0) 以上
simSlotCount = telephonyManager.PhoneCount;
}
else
{// デュアルSIMなどという軟弱な概念はない
throw new NotSupportedException();
}
Console.WriteLine($"SIM Slot count: {simSlotCount}");