Android谷歌地图v2

时间:2013-09-25 06:58:31

标签: android google-maps google-maps-android-api-2 google-play-services

有没有办法确保设备上安装了最新的Google服务?如果没有在应用程序上显示地图而没有应用程序崩溃?

3 个答案:

答案 0 :(得分:1)

希望有所帮助

public boolean isGoogleMapsInstalled()
{
    try
    {
        ApplicationInfo info = getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0 );
        return true;
    } 
    catch(PackageManager.NameNotFoundException e)
    {
        return false;
    }
}

答案 1 :(得分:1)

您可以致电:

int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable();

if(code == ConnectionResult.SUCCESS) {
    // google play services are up to date
} else {
    // get dialog to fix issue
    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(code, this, REQUEST_GPS_ERROR_DIALOG);
}

答案 2 :(得分:1)

试试这种方式

private boolean checkPlayServices() {
        int resultCode = GooglePlayServicesUtil
                .isGooglePlayServicesAvailable(this);
        if (resultCode != ConnectionResult.SUCCESS) {
            return false;
        }else{
                   GooglePlayServicesUtil.getErrorDialog(resultCode, this,
                    9000).show();
            }
        return true;
    }