I'm new in Android.My phone has two SIM slot,And i want to know secomd SIM card's info.So I want to sue the blowe method in TelephonyManager which is hided.
Someone tells me to use reflect,and here is my try.
Class<TelephonyManager> telephonyManagerClass = TelephonyManager.class;
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
try {
Method method = telephonyManagerClass.getMethod("getSimState", new Class[]{int.class});
method.setAccessible(true);
Object object = method.invoke(telephonyManager,1);
int a = (int)object;
System.out.println(a);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}catch (Exception e){
e.printStackTrace();
}
Unfortunatly, here is exception
java.lang.NoSuchMethodException: getSimState [int]
at java.lang.Class.getConstructorOrMethod(Class.java:472)
at java.lang.Class.getMethod(Class.java:857)
at (MainActivity.java:61)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18442)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5195)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:603)
at dalvik.system.NativeStart.main(Native Method)
Could you help me to fix it?
Aucun commentaire:
Enregistrer un commentaire