【问题标题】:Google Maps Android API v2: GooglePlayServicesNotAvailableException not thrown anymoreGoogle Maps Android API v2:GooglePlayServicesNotAvailableException 不再抛出
【发布时间】:2014-07-26 09:31:42
【问题描述】:

将 Google Play 服务更新到版本 18 后,似乎无法再使用 GooglePlayServicesNotAvailableException。这段代码:

try {
    MapsInitializer.initialize(ctx);
} catch (GooglePlayServicesNotAvailableException e) {
    e.printStackTrace();
}

产生这个错误:

GooglePlayServicesNotAvailableException 的无法到达的 catch 块。 try 语句体永远不会抛出这个异常

我现在怎样才能达到同样的效果? 谢谢

【问题讨论】:

  • 不清楚你在说什么“相同的结果”。请详细说明
  • @kgandroid 我想保留安全代码,捕获异常。
  • 好的...那么你可以使用catch(Exception e){e.printstacktrace()//或你想在catch中做的任何事情}
  • @kgandroid 谢谢,但我知道。我想了解的是我是否可以使用另一段代码,与 Google Play 服务的最新版本一致。类似于 GooglePlayServicesNotAvailableException 的东西。
  • 你可以这样使用:int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext); if (checkGooglePlayServices != ConnectionResult.SUCCESS) { // google play 服务丢失!!! /* 返回指示是否有错误的状态码。 ConnectionResult 中可以是以下之一:SUCCESS、SERVICE_MISSING、SERVICE_VERSION_UPDATE_REQUIRED、SERVICE_DISABLED、SERVICE_INVALID。 */ GooglePlayServicesUtil.getErrorDialog(checkGooglePlayServices, mActivity, 1122).show(); }

标签: android google-maps android-maps-v2 android-maps


【解决方案1】:

现在函数initialize() 返回一个ConnectionResult,所以你可以这样做:

if (MapsInitializer.initialize(ctx) != ConnectionResult.SUCCESS) {
    // Handle the error
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多