Security exception when accessing simcard on android emulator

440 views Asked by At

I just wrote below code, and running on an android emulator:

        TelephonyManager mgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String t = "";
        try {
            t = mgr.getSimSerialNumber();
        } catch (Exception e) {
            e.printStackTrace();
        }

I've got following exception:

java.lang.SecurityException: getIccSerialNumber: Neither user 10057 nor current process has android.permission.READ_PHONE_STATE.

Permissions were added in app's 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" />

The code can be executed on a real device without error. I'm wondering is it possible to get a fake sim card info (better be configurable) on an android emulator instead of throwing security exception?

0

There are 0 answers