android 判断连接的网络是移动?联通?电信?

项目实例:
地图的显示问题,不同的网络需要不同的访问地址。

 public Context mcontext;//声明context
    private MapView mMapView;
    public GraphicsLayer[] mLayerArray; // 图层
    String mapUrl ="http://aaaaaaaaaaaa";//移动外网地址
    String ltMapUrl="http://bbbbbbbbbbbb";//联通
    String dxMapUrl="http://ccccccccccccc";//联通
    
     TelephonyManager  telephonyManager = (TelephonyManager) mcontext.getSystemService(Context.TELEPHONY_SERVICE);
        String IMSI = telephonyManager.getSubscriberId();//获取SIM卡的IMSI
        if (IMSI.length() > 0){
	        if (IMSI.substring(0, 5).equals("46000") || IMSI.substring(0, 5).equals("46002")){//通过前五位判断连的wifi或者数据流量是移动、联通还是电信
	        	//移动
	        }else if (IMSI.substring(0, 5).equals("46001")){
	        	//联通
	        	mapUrl=ltMapUrl;
	        }else if (IMSI.substring(0, 5).equals("46003")){
	        	//电信
	        	mapUrl=dxMapUrl;
	        }
        }
        mDynamicServiceLayer = new ArcGISDynamicMapServiceLayer(mapUrl);
        mMapView.addLayer(mDynamicServiceLayer); // 在线地图的图层,动态绘制的图层
//备注:不插卡的话,IMSI =null,IMSI.length()会报错,可以加判断
	if(IMSI==null){
        	//mapUrl=ltMapUrl;
        	mapUrl=mapUrl;//不插卡用移动url
        }
//备注:不插卡的话,什么的WiFi用什么样的url也是可以看见地图的
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值