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

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

 public Context mcontext;
    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();
        if (IMSI.length() > 0){
	        if (IMSI.substring(0, 5).equals("46000") || IMSI.substring(0, 5).equals("46002")){
	        	//移动
	        }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); // 在线地图的图层,动态绘制的图层

猜你喜欢

转载自blog.csdn.net/zcaixx/article/details/84616226