下面的代码可以在模拟器和某些设备上完美运行。 LG和中兴设备100%工作。但是,在三星和华为等大多数其他设备上,我需要绘制的POI不起作用。其他所有工作都包括通过phonestatelistener进行的网络测量。在非功能性设备上,应用程序会打开一个显示Google地图但没有显示POI的设备。我试过在不同的地方调用makeSite()方法,它没有任何区别。
关于我做错的任何想法。我是Android编码的新手,所以在这个阶段失去了:
enter code here@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
requestforPermission();
psListener = new myPhoneStateListener();
telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(psListener, myPhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
public void makeSite() throws IOException, BiffException {
double latitude;
double longitude;
try {
AssetManager assetManager = getAssets();
InputStream inputStream = assetManager.open("NewFile.xls");
Workbook workbook = Workbook.getWorkbook(inputStream);
Sheet sheet = workbook.getSheet(0);
for (int Row = 1; Row < 5010; Row++) {
Cell siteNameCell = sheet.getCell(0, Row);
Cell latitudeCell = sheet.getCell(1, Row);
Cell longitudeCell = sheet.getCell(2, Row);
Cell siteRevCellH = sheet.getCell(4, Row);
Cell siteRevCellA = sheet.getCell(5, Row);
Cell siteRevCellB = sheet.getCell(6, Row);
Cell siteRevCellU = sheet.getCell(7, Row);
latitude = Double.parseDouble(latitudeCell.getContents());
longitude = Double.parseDouble(longitudeCell.getContents());
siteName = siteNameCell.getContents();
siteRevH = java.lang.Boolean.parseBoolean(siteRevCellH.getContents());
siteRevA = java.lang.Boolean.parseBoolean(siteRevCellA.getContents());
siteRevB = java.lang.Boolean.parseBoolean(siteRevCellB.getContents());
siteRevU = java.lang.Boolean.parseBoolean(siteRevCellU.getContents());
towerLatLong = new LatLng(latitude, longitude);
if (siteRevH == true) {
siteHigh(towerLatLong, siteName);
} else if (siteRevA == true) {
siteAbove(towerLatLong, siteName);
} else if (siteRevB == true) {
siteBelow(towerLatLong, siteName);
} else if (siteRevU == true) {
positionSite(towerLatLong, siteName, siteChurn);
}
}
} catch (Exception e) {
}
}
public void positionSite(LatLng towerLatLong, String siteName, String siteChurn) {
MarkerOptions options = new MarkerOptions()
.icon(BitmapDescriptorFactory.fromAsset("ctower1.png"))
.title(siteName)
.position(towerLatLong);
mMap.addMarker(options);
}
public void siteHigh(LatLng towerLatLong, String siteName) {
MarkerOptions options = new MarkerOptions()
.icon(BitmapDescriptorFactory.fromAsset("ctower1.png"))
.title(siteName)
.position(towerLatLong);
mMap.addMarker(options);
}
public void siteAbove(LatLng towerLatLong, String siteName) {
MarkerOptions options = new MarkerOptions()
.icon(BitmapDescriptorFactory.fromAsset("ctower1.png"))
.title(siteName)
.position(towerLatLong);
mMap.addMarker(options);
}
public void siteBelow(LatLng towerLatLong, String siteName) {
MarkerOptions options = new MarkerOptions()
.icon(BitmapDescriptorFactory.fromAsset("ctower1.png"))
.title(siteName)
.position(towerLatLong);
mMap.addMarker(options);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
try {
makeSite();
LatLng site = towerLatLong;
String name = siteName;
mMap.moveCamera(CameraUpdateFactory.newLatLng(site));
//mMap.moveCamera(CameraUpdateFactory.newLatLngZoom((site), 16.0f));
setUpMap();
} catch (Exception e) {
toast = Toast.makeText(this, "caught :" + e.getMessage(), toast.LENGTH_SHORT);
}
}
public void setUpMap() throws IOException, BiffException {
UiSettings Ui;
Ui = mMap.getUiSettings();
Ui.setZoomControlsEnabled(true);
Ui.setCompassEnabled(true);
Ui.setAllGesturesEnabled(true);
mMap.setBuildingsEnabled(true);
mMap.setMapType(mMap.MAP_TYPE_NORMAL);
mMap.setMyLocationEnabled(true);
mMap.setPadding(0, 70, 0, 0);
//makeSite();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mMap.setMyLocationEnabled(true);
} else {
}
} else {
}
mMap.setMyLocationEnabled(true);
}
@TargetApi(24)
public void requestforPermission() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, CODE_ACCESS_COARSE);
}
}
public class myPhoneStateListener extends PhoneStateListener {
public int netId;
public int netId2;
public int netId3;
public int netId4;
public int netId5;
public int netId6;
public double netId7;
public int NetType;
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
super.onSignalStrengthsChanged(signalStrength);
NetType = telephonyManager.getNetworkType();
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> cellInfo = telephonyManager.getAllCellInfo();
if (cellInfo != null) {
for (int i = 0; i < cellInfo.size(); i++) {
if (cellInfo.get(i).isRegistered()) {
if (cellInfo.get(i) instanceof CellInfoWcdma) {
CellInfoWcdma cellInfoWcdma = (CellInfoWcdma) telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthWcdma cellSignalStrengthWcdma = cellInfoWcdma.getCellSignalStrength();
CellIdentityWcdma cellIdentityWcdma = cellInfoWcdma.getCellIdentity();
netId3 = cellSignalStrengthWcdma.getAsuLevel();
netId2 = netId3 - 116;
netId = cellIdentityWcdma.getCid() & 0xffff;
netId4 = cellIdentityWcdma.getLac();
} else if (cellInfo.get(i) instanceof CellInfoGsm) {
CellInfoGsm cellInfogsm = (CellInfoGsm) telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthGsm cellSignalStrengthGsm = cellInfogsm.getCellSignalStrength();
CellIdentityGsm cellIdentityGsm = cellInfogsm.getCellIdentity();
netId = cellIdentityGsm.getCid() & 0xffff;
netId2 = (2 * netId3) - 113;
netId3 = cellSignalStrengthGsm.getAsuLevel();
netId4 = cellIdentityGsm.getLac();
} else if (cellInfo.get(i) instanceof CellInfoLte) {
CellInfoLte cellInfoLte = (CellInfoLte) telephonyManager.getAllCellInfo().get(0);
CellSignalStrengthLte cellSignalStrengthLte = cellInfoLte.getCellSignalStrength();
CellIdentityLte cellIdentityLte = cellInfoLte.getCellIdentity();
netId = cellIdentityLte.getCi() / 256;
netId3 = cellSignalStrengthLte.getAsuLevel();
netId2 = netId3 - 140;
netId4 = cellIdentityLte.getTac();
}
}
}
}
if (NetType == 13) {
setTextViewTextThree(String.valueOf("Node ID:" + (netId)) + " " + "RSRP:" + (netId2) + " " + "TAC:" + (netId4));
} else if (NetType == 3 || NetType == 10 || NetType == 8 || NetType == 15) {
setTextViewTextThree(String.valueOf("Cell ID:" + (netId)) + " " + "RSCP:" + (netId2) + " " + "LAC:" + (netId4));
} else if (NetType == 2) {
setTextViewTextThree(String.valueOf("Cell ID:" + (netId)) + " " + "RxLev:" + (netId2) + " " + "LAC:" + (netId4));
}
}
}
public void setTextViewTextThree(String s) {
((TextView) findViewById(R.id.rxLevel)).setText(s);
}
}