It is possible. I do this in this code:
try { @SuppressWarnings("rawtypes") Class clazz = Class.forName(telephonyManager.getClass().getName()); Method m = clazz.getDeclaredMethod("getITelephony"); m.setAccessible(true); ITelephony it = (ITelephony) m.invoke(telephonyManager); if (it.supplyPin("1234")) { // SIM unlocked } else { // not unlocked } } catch (Exception e) { // }
For this, you will need the ITelephony interface. Here you can find its source. Make the com.android.internal.telephony package in your src folder and put iTelephony.java. This approach uses the * android.permission.MODIFY_PHONE_STATE * permission, available only for Android 2.2. Starting with version 2.3, this permission is limited by system applications. If you want to use this code in the latest version, you need to transfer the apk file of the application from / data / app to the / system / app folder.
source share