android 双卡获取电话号码,Android开发——反射获取双卡Sim卡信息

直接封装出来一个工具类,记录一下android

package com.dreamroom.device;

import java.lang.reflect.Method;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import org.json.JSONArray;

import org.json.JSONObject;

import android.telephony.TelephonyManager;

public class SimUtils {

public JSONArray getAllSimInfo(TelephonyManager tel) throws Exception {

Class> clazz = tel.getClass();

//获取能够进行反射的字段

List list = new ArrayList<>();

Map listIgnore = new HashMap<>();

Method[] methods = clazz.getDeclaredMethods();

for(Method method : methods) {

String name = method.getName();

if(!name.startsWith("get"))

continue;

if(listIgnore.get(name) != null)

continue;

listIgnore.put(name, 0);

Method m1 = null;

Method m2 = null;

Method m3 = null;

try {m1 = clazz.getDeclaredMethod(name); } catch(Exception e) {}

try {m2 = clazz.getDeclaredMethod(name, int.class); } catch(Exception e) {}

try {m3 = clazz.getDeclaredMethod(name, long.class); } catch(Exception e) {}

if(m1 != null && ((m2 == null && m3 != null) || (m2 != null && m3 == null))) {

Class> c1 = m1.getReturnType

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值