Search code examples
androidreflectionsms-gateway

How to get SmsManager object of selected SIM card using 'Java Reflection'?


I'm using reflection method for get smsManager object of SIM card.

It working perfectly to get default smsManager object of default SIM by using "getDefault" method,

getContext().getClassLoader().loadClass("android.telephony.SmsManager").getMethod("getDefault", new Class[0]).invoke(null, new Object[0]);

But I want to send messages from selected SIM card (option given to select SIM card in my application).

I know, there is a method in SmsManager class to get smsManager object of selected SIM card using SIM subscriptionID 'getSmsManagerForSubscriptionId(int subscriptionID)' added in API level 22 (lollipop).

It works perfectly using below code,

SmsManager.getSmsManagerForSubscriptionId(subscriptionID);

But I want to using by reflection method. So,when I'm using this method by reflection,

getContext().getClassLoader().loadClass("android.telephony.SmsManager").getMethod("getSmsManagerForSubscriptionId", Integer.class).invoke(null, subID);

It throws exception : 'java.lang.NoSuchMethodException: getSmsManagerForSubscriptionId [class java.lang.Integer]'

Can anyone tell me where I'm doing wrong?

Thanks.


Solution

  • Integer is not int.

    int.class instead of Integer.class