要獲取SIM卡的信息,您可以使用TelephonyManager類的getSimOperator()、getSimOperatorName()、getSimState()等方法。以下是一個示例代碼:
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String simOperator = telephonyManager.getSimOperator();
String simOperatorName = telephonyManager.getSimOperatorName();
int simState = telephonyManager.getSimState();
Log.d("SIM Info", "SIM Operator: " + simOperator);
Log.d("SIM Info", "SIM Operator Name: " + simOperatorName);
Log.d("SIM Info", "SIM State: " + simState);
請注意,您需要在AndroidManifest.xml文件中添加相應的權限:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
這樣您的應用程序就可以訪問設備的電話狀態信息了。