2014-09-25 59 views
-1

我正在制作使用Google Maps API v2的Android应用程序。 由于它需要一些最新版本的Google Play服务,我在OnResume()中添加了以下代码。用户更新Google Play服务时出错

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); 

// Check Google Play Service Available 
try { 
    if (status != ConnectionResult.SUCCESS) { 
     GooglePlayServicesUtil.getErrorDialog(status, this, 10, new DialogInterface.OnCancelListener() { 

      @Override 
      public void onCancel(DialogInterface dialog) { 
       // TODO Auto-generated method stub 
       Runnable r = new Runnable() { 

        @Override 
        public void run() { 
         // TODO Auto-generated method stub 
         onBackPressed(); 

        } 

       }; 
       r.run(); 
      } 
     }).show(); 
    } 
} catch (Exception e) { 
    Log.e("Error: GooglePlayServiceUtil: ", "" + e); 

} 

它工作正常,在手机与Android 4.4及以上(当手机没有最新版本的警告对话框弹出,当我点击确定谷歌的播放服务的更新页面出现),但在安卓4.0当我点击确定时它崩溃。

我只是无法弄清楚为什么会发生这种情况。 在logcat中, 我得到一些空指针异常

at android.app.Instrumentation.execStartActivity 
at android.app.Activity.startActivityForResult 
at android.support.v4.app.FragmentActivity.startActivityForResult 

所以,我怎么会有旧的操作系统的用户去更新页面,对吗?

回答

1

试试这个

  if (GooglePlayServicesUtil.isUserRecoverableError(status)) { 
       GooglePlayServicesUtil.getErrorDialog(status, this, 10, new DialogInterface.OnCancelListener() { 

        @Override 
        public void onCancel(DialogInterface dialog) { 
         // TODO Auto-generated method stub 
         Runnable r = new Runnable() { 

          @Override 
          public void run() { 
           // TODO Auto-generated method stub 
           onBackPressed(); 

          } 

         }; 
         r.run(); 
        } 
       }).show(); 
      } else { 
       Toast.makeText(this, "This device is not supported.", Toast.LENGTH_LONG).show(); 
       finish(); 
      } 
+0

听起来合法的。我会试试看。 thx ..顺便说一下,我添加了一个intent到谷歌播放服务上的谷歌播放服务后的吐司代码的互联网网页。 – user345 2014-09-25 12:20:05

+0

它很好用。谢谢... – user345 2014-10-01 05:44:22

相关问题