Hi, you can start referring to TelephonyManager. This class helps you access the information regarding the SIM upto an extent. However to access certain data like messages in SIM, we have to use SmsManager and SmsMessage.
Also, note that there are few hidden/internal methods that we can access with Reflection. However we can't be certain if those methods exist internally.
Packages required for the code to work:
import android.telephony.SmsMessage;
import java.lang.reflect.Method;
Actual code:
ArrayList<SmsMessage> list = new ArrayList<SmsMessage>();
try {
Class<?> smsMgrClass = Class.forName("android.telephony.SmsManager");
Method getSMSMgr = smsMgrClass.getMethod("getDefault");
Object smsDefaultInstance = getSMSMgr.invoke(null);
Method getMessages = smsMgrClass.getMethod("getAllMessagesFromIcc"); // this is internal method.
@SuppressWarnings("unchecked")
list = (ArrayList<SmsMessage>) getMessages.invoke(smsDefaultInstance);
Log.d("sms manager", "length: " + list.size());
} catch (Exception e) {
e.printStackTrace();
}
I will keep you updated if I find any alternate options.
Hope this helps!