get Sim Info By Slot - Android Phone

Android examples for Phone:Sim

Description

get Sim Info By Slot

Demo Code


import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.BaseColumns;
import android.telephony.TelephonyManager;
import java.lang.reflect.Method;

public class Main{
    /*  www. j  a  v  a2  s .  co  m*/
    public static SimCardInfo getSimInfoBySlot(Context context, int slotID) {
        if (context == null || slotID < 0) {
            return null;
        }

        try {
            Cursor cursor = context.getContentResolver().query(
                    SimInfo.CONTENT_URI, null, SimInfo.SLOT + "=?",
                    new String[] { String.valueOf(slotID) }, null);
            try {
                if (cursor != null) {
                    if (cursor.moveToFirst()) {
                        return fromCursor(cursor);
                    }
                }
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
        } catch (Exception e) {

        }
        return null;
    }
    
    public static SimCardInfo fromCursor(Cursor cursor) {
        if (cursor == null) {
            return null;
        }

        SimCardInfo info = new SimCardInfo();
        try {
            info.mSimId = cursor.getLong(cursor
                    .getColumnIndexOrThrow(DoubleSimPhoneUtil.SimInfo._ID));
            info.mICCId = cursor.getString(cursor
                    .getColumnIndexOrThrow(SimInfo.ICC_ID));
            info.mDisplayName = cursor.getString(cursor
                    .getColumnIndexOrThrow(SimInfo.DISPLAY_NAME));
            info.mNumber = cursor.getString(cursor
                    .getColumnIndexOrThrow(SimInfo.NUMBER));
            info.mDispalyNumberFormat = cursor.getInt(cursor
                    .getColumnIndexOrThrow(SimInfo.DISPLAY_NUMBER_FORMAT));
            info.mColor = cursor.getInt(cursor
                    .getColumnIndexOrThrow(SimInfo.COLOR));
            info.mDataRoaming = cursor.getInt(cursor
                    .getColumnIndexOrThrow(SimInfo.DATA_ROAMING));
            info.mSlot = cursor.getInt(cursor
                    .getColumnIndexOrThrow(SimInfo.SLOT));
        } catch (Exception e) {

        }
        return info;
    }
}

Related Tutorials