top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Android:Read data from the phone SIM card?

+2 votes
528 views

I am writing an Android application that will need to read data from the phone SIM card such as messages stored in the SIM card.
I am stuck where do I get a start tutorial or guide.

posted Aug 31, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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!

answer Sep 1, 2016 by Vinod Kumar K V
Similar Questions
+1 vote

I am trying to detect Cellular signals without an installed SIM card. The phone I'm using is a Motorola Nexus 6. And the code I am using is below -

tm  = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cInfoList = tm.getAllCellInfo();  

for (final CellInfo info : cInfoList) {
  if (info instanceof CellInfoGsm) 
     sR =  "GSM: " + gsm.toString() + "\n" + ((CellInfoGsm) info).getCellIdentity();
  else if (info instanceof CellInfoCdma) 
     sR =  "CDMA: " + cdma.toString() + "\n" + ((CellInfoCdma) info).getCellIdentity();
  else if (info instanceof CellInfoLte) 
     sR =  "LTE: " + lte.toString() + "\n" + ((CellInfoLte) info).getCellIdentity();
  else if (info instanceof CellInfoWcdma) 
     sR =  "WCDMA: " + wcdma.toString() + "\n" + ((CellInfoWcdma) info).getCellIdentity();

When the SIM slot is empty, cInfoList contains only objects of CellInfoGsm and CellInfoWcdma, which are 3G. If I insert a SIM card and let it connect, then cInfoList contains only instances of CellInfoLte, which is 4G.

Can you explain me why I cannot detect LTE cell networks without a SIM card and why I cannot detect 3G networks with a SIM card?

+1 vote

Usually Iphones etc are locked with some operator e.g. AT&T etc which then onwards cannot be used with others unless these gets unlocked with s/w upgrade etc.

My question is about making this locking configurable with a SIM[s] and not with an operator. This is to address the phone thefts etc. This way the users can lock the phone with a particular SIM. This locking can be removed later by users themselves. This may also need the operators/phone manufacturers support based on the mechanism. Here any s/w only mechanism may be forcefully overridden upon the wholesale reformat hence some device level support may be needed.

I am not sure if this mechanism already exists.

+1 vote

Want to get the cellid for my app, can someone share the code for LTE-Android?

+1 vote

I'm trying to get my sdcard to automount on my nexus 10 through USB OTG cable. I can manually mount it and it works. Here is what I have setup so far. Is there anything else I need to do? I manually mount it like

"mount -t vfat /dev/block/sda1 /mnt/usbdisk"

init.manta.rc
 # usb usb sd card
 export SECONDARY_STORAGE /storage/usbdisk0
 mkdir /storage/usbdisk0 0666 system system

 symlink /storage/usbdisk0 /usbdisk
 symlink /storage/usbdisk0 /mnt/usbdisk

vold.fstab
dev_mount usbdisk /storage/usbdisk0 auto /dev/block/sda1
+1 vote

Is it possible to create a tool to switch sim 1 and sim 2 , on and off separately. If possible with a timer?
I want my sim2 , business calls , shut down when workday is over and on when in start in the morning.

...