2013-03-09 79 views
1

我已经成功工作android maps API v2,但后来我试图测试如果我没有Google Play服务,应用程序会提供安装它。android地图v2提供播放服务

因此,我卸载了Google Play服务,现在我的应用程序崩溃了。它不像安装示例应用程序那样提供安装Google Play服务。在LogCat中它的打印Google play services is missingNullPointerException之后。在示例应用程序中,我没有看到任何处理该代码的代码,我想它包含在地图库中。我使用SupportMapFragment,但在示例应用程序中也使用它。

如何使应用程序提供安装播放服务,就像它在示例应用程序?

+0

此链接将有助于http://stackoverflow.com/questions/13691028/noclassdeffounderror-at-google-play-services-v2-library – DjHacktorReborn 2013-03-09 21:01:44

回答

5

您可以使用GooglePlayServicesUtil类。您的代码将是这个样子:

int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); 
if (resultCode == ConnectionResult.SUCCESS) 
{ 
    // Google Play Services installed correctly, continue 
} 
else if (resultCode == ConnectionResult.SERVICE_MISSING || 
     resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED || 
     resultCode == ConnectionResult.SERVICE_DISABLED) 
{   
    // Google Play Services not installed/too old/disabled. 
    // Show dialog to install or update 
    Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 1); 
    dialog.show(); 
} 
else 
{ 
    // Something else went wrong, handle this yourself 
} 

getErrorDialog方法表明,将用户引导到谷歌Play商店安装或更新谷歌播放服务的对话框。