我刚刚编写了下面的代码,并在Android模拟器上运行:
TelephonyManager mgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
String t = "";
try {
t = mgr.getSimSerialNumber();
} catch (Exception e) {
e.printStackTrace();
}
我有以下例外:
java.lang.SecurityException: getIccSerialNumber: Neither user 10057 nor current process has android.permission.READ_PHONE_STATE.
在应用的AndroidManifest.xml中添加了权限:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
代码可以在真实设备上执行而不会出错。我想知道是否有可能在Android模拟器上获取假卡片信息(最好是可配置的)而不是抛出安全例外?