How to use a hidden method in Android?
<p>I'm new in Android. My phone has two SIM slots, and I want to know the second SIM card's info. So I want to use the below method in TelephonyManager which is hidden.</p>

<p><a href="https://i.stack.imgur.com/noKoq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/noKoq.png" alt="enter image description here"></a></p>

<p>Someone tell me how to use reflect, and here is my try.</p>

<pre><code>            Class&lt;TelephonyManager&gt; 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();
            }
</code></pre>

<p>Unfortunately, here is exception:</p>

<pre><code> 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)
</code></pre>

<p>Could you help me to fix it?</p>