项目实例:
地图的显示问题,不同的网络需要不同的访问地址。
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也是可以看见地图的