问题
This is my first question! I'd like to know how to access to standard settings in android, in particular SIM features. On boot, my Samsung i-9000 shows the window for insert the PIN code only for a few seconds, then disappears, so I'd like to develop by myself a widget for the homescreen that launch the standard window to insert the PIN code, but I don't know how can I do it!
Or someway to change the screen timeout of that window...
Thank you very much!
回答1:
By using the TelephonyManager in Android.
You do not instantiate this class directly; instead, you retrieve a reference to an instance through Context.getSystemService(Context.TELEPHONY_SERVICE)
TelephonyManager manager = (TelephonyManager) Context.getSystemService(Context.TELEPHONY_SERVICE);
int state = manager.getSimState();
if(state == TelephonyManager.SIM_STATE_PIN_REQUIRED || state == TelephonyManager.SIM_STATE_PUK_REQUIRED)
{
//PIN/PUK is required
}
May this will help you ...
回答2:
If you would like to apply PIN in Android above 2.3 version, you have to install your app as a system app, in both cases you should use this code:
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephonyService;
telephonyService = (ITelephony)m.invoke(tm);
// Supply SIM PIN
SharedPreferences prefs = getSharedPreferences(OrangeSignalMeterLoop.class.getCanonicalName()+"x", Context.MODE_PRIVATE);
if(prefs.getBoolean(context.getString(R.string.whetherAutoCompletePIN), false)) {
String sim_pin = prefs.getString(context.getString(R.string.pinCode), "1111");
telephonyService.supplyPin(sim_pin);
}
You probably will not be able use Internal class, the best tutorial how to use it you'll find here: https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/
来源:https://stackoverflow.com/questions/8323484/access-to-standard-android-settings-pin-code-of-the-sim-card