列出适用于Android API 17及更高版本的SIM卡信息(双SIM卡设备)

时间:2018-08-13 23:58:51

标签: java android

我正在尝试使用此内容提供程序获取双SIM卡设备的SimInfo

public static List<SimInfo> getSIMInfo(Context context) {
    List<SimInfo> simInfoList = new ArrayList<>();
    Uri URI_TELEPHONY = Uri.parse("content://telephony/siminfo/");
    Cursor c = context.getContentResolver().query(URI_TELEPHONY, null,     "slot>=0", null, null);
    if (c!=null && c.moveToFirst()) {
        do {
            int id = c.getInt(c.getColumnIndex("_id"));
            int slot = c.getInt(c.getColumnIndex("slot"));
            String display_name = c.getString(c.getColumnIndex("display_name"));
            String icc_id = c.getString(c.getColumnIndex("icc_id"));
            String number=c.getString(c.getColumnIndex("number"));
            SimInfo simInfo = new SimInfo(id, display_name, icc_id, slot, number);
            Log.d("apipas_sim_info", simInfo.toString());
            simInfoList.add(simInfo);
        } while (c.moveToNext());


        c.close();
    }       

    return simInfoList;
}

它正在API 17上运行,但对于API> = 22,Cursor返回null。

0 个答案:

没有答案