在使用谷歌地圖API的Android V2我正在關注的Google Play Services setup documentation進行檢查,以確保谷歌Play服務,安裝,使用我的主要活動如下代碼:谷歌地圖API的Android V2檢查,如果谷歌地圖安裝在設備
@Override
public void onResume()
{
checkGooglePlayServicesAvailability();
super.onResume();
}
public void checkGooglePlayServicesAvailability()
{
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(resultCode != ConnectionResult.SUCCESS)
{
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 69);
dialog.setCancelable(false);
dialog.setOnDismissListener(getOnDismissListener());
dialog.show();
}
Log.d("GooglePlayServicesUtil Check", "Result is: " + resultCode);
}
這工作正常。但是,我注意到一些較舊的Android手機(主要是2.2版本)缺少GooglePlayServices以及Google地圖應用程序本身。
的logcat會報告這個錯誤: 谷歌地圖API的Android:谷歌地圖應用程序丟失。
問題 - 我怎麼能執行一個類似的檢查上面的一個谷歌地圖的設備上的可用性?其次,如果用戶已經安裝了Google地圖,我認爲該檢查需要確保他們的安裝版本與Android Maps API的V2兼容。
更新 這是我的setupMapIfNeeded()方法,它在onCreate()的末尾被調用。這是我想,我會想確定是否安裝了谷歌地圖,並提醒用戶,看到別的塊:
private void setUpMapIfNeeded()
{
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null)
{
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.basicMap)).getMap();
if (mMap != null)
{
mMap.setLocationSource(this);
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(44.9800, -93.2636), 10.0f));
setUpMap();
}
else
{
//THIS CODE NEVER EXECUTES - mMap is non-null even when Google Maps are not installed
MapConstants.showOkDialogWithText(this, R.string.installGoogleMaps);
}
}
}
可我只是問什麼是69,你對getErrorDialog方法paramte rs? – luiscvalmeida
@luiscvalmeida 69只是請求代碼(我選擇了它)。見http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesUtil.html#getErrorDialog – DiscDev